应用程序无空闲异常导致Espresso测试失败:以下空闲条件失败ASYNC_TASKS_HAVE_IDLED

时间:2018-02-20 14:29:04

标签: android unit-testing android-espresso android-instrumentation

我的Espresso测试与Espresso版本2.2.2一起运行正常但当我将我的工作室更新为最新版本时,应用的迁移规则测试将失败并需要更新版本。
库使用

androidTestImplementation'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.1'
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestCompile 'com.android.support.test:rules:1.0.1'
    androidTestImplementation "com.android.support:support-annotations:${support}"
    implementation fileTree(include: ['*.jar'], dir: 'libs')

对于测试期间的闲置资源,我使用的是IdlingResourceSample,我也尝试idling-resource-intent-service正在使用IntentServiceBroadcastReceiver。 正如Espresso Espresso.onIdle&中存在问题Espresso IdlingResourceRegistry.sync已经报告并将在下一版本中修复。我使用IdlingRegistry进行注册。但我仍然得到AppNotIdleException Log Cat

android.support.test.espresso.AppNotIdleException: Looped for 35 iterations over 60 SECONDS. The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED.
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1538)
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:312)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at com.company.project.InstrumentedDeepLinkTest.setDeepLinkUri(InstrumentedDeepLinkTest.java:107)
at java.lang.reflect.Method.invoke(Native Method)
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.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:2075) 

我已经从developer Options

禁用了动画

在分析哪AsyncTask让我的App忙碌之后,我得到thread poolAsyncTask有很多sun.misc.Unsafe.park(Unsafe.java:299)线程池

AsyncTask #9: WAITING
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.lang.Object.wait(Native Method)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.lang.Thread.parkFor$(Thread.java:1220)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  sun.misc.Unsafe.park(Unsafe.java:299)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2013)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:410)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1036)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1098)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.lang.Thread.run(Thread.java:818)

1 个答案:

答案 0 :(得分:0)

为此Google Group thread

找到了解决方案

我的进度条正在逐渐消失,但没有将可见性设置为GONE,因此它会不断更新ui。因此,尽管进行了后台工作,并且空闲资源已设置为免费,但该应用永远不会处于空闲状态。