安卓测试项目出现错误“测试运行失败:仪器运行失败,原因是‘进程崩溃’”。

23
我的问题似乎与这里稍有不同:测试运行失败:在测试多个Android活动时,由于“进程崩溃”,导致仪表运行失败
我遵循了pdf文件中给出的步骤。我已经创建了测试项目“TestAndroidCalculatorBlackbox”(我们需要有两个项目,一个测试项目和一个主项目吗?也许这可能是原因,因为在Robotium “入门”链接中,他们要求我们为记事本创建项目),并添加了robotium-solo-5.0.1.jarrobotium-solo-1.6.0.jar这两个jar以消除下面红色错误线以下的solo.函数和jay.way package.
我附上了错误截图: Project tree and error screen shot 我的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.testcalculator"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.testcalculator" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:debuggable="true">
        <uses-library android:name="android.test.runner" />
    </application>

</manifest>

而且我已经将包添加到仪器列表中:

 c:\> adb shell pm list instrumentation
instrumentation:PACKAGE.test.test/android.test.InstrumentationTestRunner (target=PACKAGE)
instrumentation:PACKAGE.test.test.test.test.test.test/android.test.InstrumentationTestRunner (target=PACKAGE.test.test)
instrumentation:com.example.android.apis/.app.LocalSampleInstrumentation (target=com.example.android.apis)
>> instrumentation:com.testcalculator/android.test.InstrumentationTestRunner (target=com.testcalculator) <<
5个回答

67

对于那些正在迁移到或者当前使用 Androidx 的人来说,这个错误是由于使用了 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 而不是 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 导致的。

使用后者完全解决了这个错误。


3
太棒了!非常感谢您的评论。对我有用! - user225405
1
昨天我离开办公室时还在思考这个问题。而今天早上你已经为我解决了!!非常感谢你,Rowland! - Cedulio Cezar
太好了,谢谢。Android在这方面应该有更清晰的错误提示!在看到你的评论之前,我已经浪费了一个小时的工作时间。 - Forrest

11
  1. 不要附加多个robotium库。应该删除robotium-solo-1.6.0.jar。它已经过时,你真的不应该再使用它了。

  2. 你的目标应用程序已经安装了吗?如果你要为其运行测试,则应安装它。仅当你的测试项目引用目标项目时才无法安装它。

  3. 如果你有独立的应用程序和测试工具的APK文件,应该在清单中更改包名。你实际上有“com.testcalculator”,而目标包是相同的 - 它们应该是不同的。顺便说一下,我没有看到你项目中应用程序的源代码,所以应用程序部分应该被删除。

  4. 你的错误信息并没有说太多,最好从LogCat中发布堆栈跟踪。

  5. 在开始编写测试之前,请阅读手册:

    http://developer.android.com/tools/testing/testing_android.html https://code.google.com/p/robotium/w/list


太棒了,点赞!!我已经在AndroidManifest.xml中注释了应用程序部分。我看到计算器应用程序启动了,但由于错误“Test run failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'”,无法执行测试。也许LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.calculator.Main"是错误的。但我不知道它应该是什么(我已经从AndroidManifest.xml中删除了application project和应用程序标记)。 - paul
什么类找不到?使用LogCat。 - maszter
我的LogCat没有输出任何内容。 - laim2003

1

0
在我的情况下,这是由AndroidJUnitRunner引起的StrictMode策略违规。
D/StrictMode: StrictMode policy violation: android.os.strictmode.UntaggedSocketViolation: [...]
W/System.err: StrictMode VmPolicy violation with POLICY_DEATH; shutting down.

当我运行Espresso测试时,禁用检查detectUntaggedSockets()对我有帮助。请参见this question以了解如何进行检查。


0

对于尚未使用androidx的开发人员。查看 LogCat 为我解决了问题,这是因为由于RxJava在错误的线程中运行而删除这些行。

companion object {
    @get:ClassRule @JvmStatic
    val testSchedulerRule = RxImmediateSchedulerRule()
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接