发生appNotIdleException

时间:2018-05-09 06:18:36

标签: android unit-testing android-espresso

我是Android espresso测试的初学者。我想点击一个textview。如果textview没有任何值,那么点击后就可以了。

但是当textview通过做一些后台进程获得价值时,那个时候它无法正常工作。而不是它抛出了AppNotIdleException的异常。我在Stack Overflow中搜索了解决问题的方法。但我对解决这个问题没有任何想法。

我的代码是:

    @Test
    @MediumTest
    public void Test1_Spo2() throws InterruptedException 
    {

    PatientToMainActivity();

    Thread.sleep(1000);
    onView(withId(R.id.viewPager)).check(matches(withEffectiveVisibility(
    ViewMatchers.Visibility.VISIBLE)));

    onView(allOf(withId(R.id.txtSPO2),withText("SpO2")))
    .check(matches(isCompletelyDisplayed()));

   Thread.sleep(5000);
    //

   //onView(withId(R.id.imgSPO2))
   .check(matches(withDrawable(R.drawable.o2)));
    onView(withId(R.id.txtSPO2Value)).perform(click());

    Thread.sleep(1000);

    intended(hasComponent(new ComponentName(getTargetContext(),ChartActivity.class)));


}
单击txtSpo2Value后,

显示以下异常。

android.support.test.espresso.AppNotIdleException: Looped for 8778   iterations over 60 SECONDS. The following Idle Conditions failed .
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:580)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError   (DefaultFailureHandler.java:92)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at anidra.com.berryapp.MainActivityLiveFragmentTest.Test1_Spo2(MainActivityLiveFragmentTest.java:99)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
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 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
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:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1851)

1 个答案:

答案 0 :(得分:0)

据我所知,这个例外可能有一些原因:

  1. 您为自己注册的空闲资源已经死锁 考试班。您可以检查您为测试类做了什么。
  2. 你确定没有东西拿着主/ ui线程吗?去开发者 设备的设置,然后启用“显示屏幕/表面更新” 运行测试并观察被测设备的任何UI更新... 如果屏幕不断闪烁,那么事情就会不断发生 更新UI线程,因此应用程序永远不会空闲。这可以 应用程序问题,而不是测试本身。
  3. 我希望它能以某种方式帮助你......