Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android junit.framework.AssertionFailedError:donds';与所选视图不匹配_Android_Junit_Android Espresso - Fatal编程技术网

Android junit.framework.AssertionFailedError:donds';与所选视图不匹配

Android junit.framework.AssertionFailedError:donds';与所选视图不匹配,android,junit,android-espresso,Android,Junit,Android Espresso,我使用Espresso test进行仪器测试。有两个片段替换了主容器。我总是发现视图与所选视图不匹配。我检查了好几次,但没有找到错误 寄存器碎片测试 @RunWith(AndroidJUnit4.class) public class RegisterFragmentTest { private Resources resources; @Rule public IntentsTestRule<StarterActivity> mActivityInten

我使用Espresso test进行仪器测试。有两个片段替换了主容器。我总是发现视图与所选视图不匹配。我检查了好几次,但没有找到错误

寄存器碎片测试

@RunWith(AndroidJUnit4.class)
public class RegisterFragmentTest {

    private Resources resources;

    @Rule
    public IntentsTestRule<StarterActivity> mActivityIntentsTestRule = new IntentsTestRule<StarterActivity>(StarterActivity.class);

    @Before
    public void init() {
        mActivityIntentsTestRule.getActivity().getSupportFragmentManager().beginTransaction().addToBackStack(null)
                .replace(R.id.pager, new RegisterFragment()).commit();
        resources = mActivityIntentsTestRule.getActivity().getResources();
    }

    @Test
    public void imageHeaderVisibility() throws Exception {
        onView(withId(R.id.imageHeader)).check(matches(isCompletelyDisplayed()));
    }
}
主容器

  android:id="@+id/pager"
问题

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'at least 100 percent of the view's area is displayed to the user.' doesn't match the selected view.
Expected: at least 100 percent of the view's area is displayed to the user.
Got: "AppCompatImageView{id=2131296361, res-name=imageHeader, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@52cc5cb4, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}"

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:579)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:314)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at register.RegisterFragmentTest.imageHeaderVisibility(RegisterFragmentTest.java:41)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Caused by: junit.framework.AssertionFailedError: 'at least 100 percent of the view's area is displayed to the user.' doesn't match the selected view.
Expected: at least 100 percent of the view's area is displayed to the user.
Got: "AppCompatImageView{id=2131296361, res-name=imageHeader, visibility=VISIBLE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@52cc5cb4, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}"
如何解决这些问题


通过使用Viewpager解决了此问题

@Rule
public ActivityTestRule<StarterActivity> mActivityTestRule = new ActivityTestRule<>(StarterActivity.class);


@Before
public void init() throws Exception {
    onView(allOf(withId(R.id.pager), childAtPosition(childAtPosition(withId(android.R.id.content), 0), 0), isDisplayed()))
            .perform(swipeRight());
}

@Test
public void imageHeaderVisible() throws Exception {
    onView(allOf(withId(R.id.imageHeader), childAtPosition(allOf(childAtPosition(withClassName(is("android.widget.RelativeLayout")), 0)), 0)));
}
@规则
public ActivityTestRule mActivityTestRule=新的ActivityTestRule(StarterActivity.class);
@以前
public void init()引发异常{
onView(allOf(withId(R.id.pager)、childAtPosition(childAtPosition)(withId(android.R.id.content)、0)、isDisplayed())
.执行(swipeRight());
}
@试验
public void ImageHeadServiceable()引发异常{
onView(allOf(withId(R.id.imageHeader)),childAtPosition(allOf(childAtPosition)(withClassName(is)(“android.widget.RelativeLayout”)),0));
}
@Rule
public ActivityTestRule<StarterActivity> mActivityTestRule = new ActivityTestRule<>(StarterActivity.class);


@Before
public void init() throws Exception {
    onView(allOf(withId(R.id.pager), childAtPosition(childAtPosition(withId(android.R.id.content), 0), 0), isDisplayed()))
            .perform(swipeRight());
}

@Test
public void imageHeaderVisible() throws Exception {
    onView(allOf(withId(R.id.imageHeader), childAtPosition(allOf(childAtPosition(withClassName(is("android.widget.RelativeLayout")), 0)), 0)));
}