【问题标题】:Espresso Test Fail due to App not Idle Exception: The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED由于 App not Idle 异常导致 Espresso 测试失败:以下空闲条件失败 ASYNC_TASKS_HAVE_IDLED
【发布时间】:2018-02-20 14:29:04
【问题描述】:

我的 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.onIdleEspresso 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 pool 有许多与sun.misc.Unsafe.park(Unsafe.java:299) 相关的AsyncTask
线程池

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)

【问题讨论】:

  • 您的闲置资源之一似乎没有闲置。您可以发布您的空闲资源设置吗?
  • 理论上应该很简单,注册idle,设置为busy,释放它,它应该可以工作了。我已经为此工作了 4 个小时,但我无法解决它。

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


【解决方案1】:

Google Group thread上找到了解决方案

我有一个正在淡出的进度条,但没有将可见性设置为GONE,因此它不断更新用户界面。因此,尽管后台工作已完成并且空闲资源设置为空闲,但应用程序永远不会空闲。

【讨论】:

    猜你喜欢
    • 2022-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多