我很难在Android Studio中运行仪器化的测试。
当我尝试运行多个测试用例时,显示“测试框架意外退出”:
...,并且所有测试都继续在模拟器中运行,但是Android Studio无法恢复结果。
Logcat显示以下内容:
...
03-17 11:38:59.236 1699 1719 W ActivityManager: Scheduling restart of crashed service androidx.test.orchestrator/.OrchestratorService in 1000ms
03-17 11:38:59.236 1699 1719 W ActivityManager: Crash of app androidx.test.orchestrator running instrumentation ComponentInfo{androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestOrchestrator}
03-17 11:38:59.236 1699 1721 W zygote : kill(-8537, 9) failed: No such process
03-17 11:38:59.238 1699 13861 W Binder : Outgoing transactions from this process must be FLAG_ONEWAY
03-17 11:38:59.238 1699 13861 W Binder : java.lang.Throwable
03-17 11:38:59.238 1699 13861 W Binder : at android.os.BinderProxy.transact(Binder.java:752)
03-17 11:38:59.238 1699 13861 W Binder : at android.app.IInstrumentationWatcher$Stub$Proxy.instrumentationFinished(IInstrumentationWatcher.java:160)
03-17 11:38:59.238 1699 13861 W Binder : at com.android.server.am.InstrumentationReporter$MyThread.run(InstrumentationReporter.java:86)
03-17 11:38:59.281 1699 1721 W zygote : kill(-8537, 9) failed: No such process
03-17 11:38:59.323 1699 1721 W zygote : kill(-8537, 9) failed: No such process
03-17 11:38:59.353 13845 13845 W app_process: Unexpected CPU variant for X86 using defaults: x86
03-17 11:38:59.362 1699 1721 W zygote : kill(-8537, 9) failed: No such process
03-17 11:38:59.385 1699 1741 W PackageManager: Code path for androidx.test.orchestrator changing from /data/app/androidx.test.orchestrator-fgDRlA7iNSNiyWm4dLj4hg== to /data/app/androidx.test.orchestrator-6QljegpCqjAHwDuS_O9G9Q==
03-17 11:38:59.385 1699 1741 W PackageManager: Resource path for androidx.test.orchestrator changing from /data/app/androidx.test.orchestrator-fgDRlA7iNSNiyWm4dLj4hg== to /data/app/androidx.test.orchestrator-6QljegpCqjAHwDuS_O9G9Q==
03-17 11:38:59.424 13845 13870 W MessageQueue: Handler (android.os.Handler) {9320712} sending message to a Handler on a dead thread
03-17 11:38:59.424 13845 13870 W MessageQueue: java.lang.IllegalStateException: Handler (android.os.Handler) {9320712} sending message to a Handler on a dead thread
03-17 11:38:59.424 13845 13870 W MessageQueue: at android.os.MessageQueue.enqueueMessage(MessageQueue.java:545)
03-17 11:38:59.424 13845 13870 W MessageQueue: at android.os.Handler.enqueueMessage(Handler.java:662)
03-17 11:38:59.424 13845 13870 W MessageQueue: at android.os.Handler.sendMessageAtTime(Handler.java:631)
03-17 11:38:59.424 13845 13870 W MessageQueue: at android.os.Handler.sendMessageDelayed(Handler.java:601)
03-17 11:38:59.424 13845 13870 W MessageQueue: at android.os.Handler.post(Handler.java:357)
03-17 11:38:59.424 13845 13870 W MessageQueue: at android.os.ResultReceiver$MyResultReceiver.send(ResultReceiver.java:57)
03-17 11:38:59.424 13845 13870 W MessageQueue: at com.android.internal.os.IResultReceiver$Stub.onTransact(IResultReceiver.java:58)
03-17 11:38:59.424 13845 13870 W MessageQueue: at android.os.Binder.execTransact(Binder.java:697)
03-17 11:38:59.436 13768 13850 W zygote : Long monitor contention with owner firebase-iid-executor (13808) at void java.lang.AbstractStringBuilder.ensureCapacityInternal(int)(AbstractStringBuilder.java:124) waiters=0 in java.util.TimeZone java.util.TimeZone.getTimeZone(java.lang.String) for 114ms
03-17 11:38:59.519 13768 13768 W ResourceType: Failure getting entry for 0x7f0c0112 (t=11 e=274) (error -75)
03-17 11:38:59.520 13768 13768 W ResourceType: Failure getting entry for 0x7f0c0113 (t=11 e=275) (error -75)
03-17 11:38:59.608 1571 1809 E : Couldn't opendir /data/app/vmdl185214765.tmp: No such file or directory
03-17 11:38:59.608 1571 1809 E installd: Failed to delete /data/app/vmdl185214765.tmp: No such file or directory
03-17 11:38:59.695 1699 1719 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:androidx.test.orchestrator flg=0x4000010 (has extras) } to com.google.android.gms/.games.chimera.GamesSystemBroadcastReceiverProxy
03-17 11:38:59.702 1699 1719 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:androidx.test.orchestrator flg=0x4000010 (has extras) } to com.google.android.gms/.photos.autobackup.PhotosAppUninstalledReceiver
...
我的测试依赖项:
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
androidTestImplementation ('androidx.test.espresso:espresso-contrib:3.2.0') {
exclude module: 'support-compat'
}
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestUtil 'androidx.test:orchestrator:1.2.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
我发现很少有引用“测试框架意外退出”和“此过程中的传出事务必须为FLAG_ONEWAY”来禁用Android Studio中的即时运行,但是由于3.5没有即时运行,因此将其重命名为“应用”代码更改,并且看不到任何选项可以将其关闭。
有什么想法要继续吗?
请帮助。
答案 0 :(得分:9)
我使用的是 AS 4.1.1,如果您使用 fragment-testing
工件,该错误仍然存在。上述解决方案均无效。
就我而言,解决问题的是从工件中排除 core
依赖
debugImplementation ("androidx.fragment:fragment-testing:1.2.5", {
exclude group: 'androidx.test', module: 'core'
})
答案 1 :(得分:6)
在 Android Studio 4.1 中出现相同的错误,添加以下依赖项
androidTestImplementation "androidx.test.espresso:espresso-core:x.x.x"
随着添加
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
解决了问题
答案 2 :(得分:4)
似乎是AS 3.6的错误。
根据Reddit中的该线程:https://www.reddit.com/r/androiddev/comments/f9xsz2/anyone_else_having_issues_running_androidtest/
它将在3.6.2。中修复。
答案 3 :(得分:3)
作为一个完整的测试初学者,当我没有在我的模块级 build.gradle 文件中添加 - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 时,我得到了这个错误。 >
其他人可能不是这种情况,但我在添加它时解决了这个问题。 根据{{3}}
<块引用>要使用 JUnit 4 测试类,请确保指定 AndroidJUnitRunner 作为项目中的默认测试仪器运行器 在您的应用程序的模块级别中包括以下设置 build.gradle 文件:
所以你可以试试添加这个。
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
答案 4 :(得分:1)
Vitor Carvalho是正确的,这是一个Android Studio v3.6.1问题。我通过卸载Android Studio来解决它,然后降级到v3.5.3。
要卸载Android Studio,follow this answer's guidance基本上可以归结为:
在终端中执行以下命令(不包括带有标签的行-它们是注释):
# Deletes the Android Studio application # Note that this may be different depending on what you named the application as, or whether you downloaded the preview version rm -Rf /Applications/Android\ Studio.app # Delete All Android Studio related preferences # The asterisk here should target all folders/files beginning with the string before it rm -Rf ~/Library/Preferences/AndroidStudio* # Deletes the Android Studio's plist file rm -Rf ~/Library/Preferences/com.google.android.* # Deletes the Android Emulator's plist file rm -Rf ~/Library/Preferences/com.android.* # Deletes mainly plugins (or at least according to what mine (Edric) contains) rm -Rf ~/Library/Application\ Support/AndroidStudio* # Deletes all logs that Android Studio outputs rm -Rf ~/Library/Logs/AndroidStudio* # Deletes Android Studio's caches rm -Rf ~/Library/Caches/AndroidStudio* # Deletes older versions of Android Studio rm -Rf ~/.AndroidStudio*
然后,从Android Studio archive安装以前版本的Android Studio。
答案 5 :(得分:0)
正如Victor Carbalho所述,这是Android Studio 3.6.1中的错误 https://stackoverflow.com/a/60727631/2353939
我现在只是禁用协调器。
testOptions {
// execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
dependencies {
// androidTestUtil 'androidx.test:orchestrator:1.2.0'
}
答案 6 :(得分:0)
删除或评论以下内容并不能解决实际目的:
testOptions {
// execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
dependencies {
// androidTestUtil 'androidx.test:orchestrator:1.2.0'
}
根据建议https://developer.android.com/training/testing/junit-runner#ato-gradle,我们应该使用它。
我也遇到了同样的问题,例如在运行测试用例时,由于我使用的是3.6.1 android studio版本,消息“框架意外退出”。
将android studio更新为 4.0.1 版本后,此问题已解决。 现在,我可以成功执行所有测试用例了。
答案 7 :(得分:0)
当我在 Android 4.1 上执行 File->Invalidate Caches and Restart 时,它对我有用,