Android 测试项目因错误“测试运行失败:由于‘进程崩溃’而导致仪器运行失败。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21605221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:49:00  来源:igfitidea点击:

Android test project is crashing with error "Test run failed: Instrumentation run failed due to 'Process crashed.'"

androidautomationrobotium

提问by paul

My problem seems little different than here Test run failed: Instrumentation run failed due to 'Process crashed.' when testing multiple Android activity
I have followed steps given in the pdf. I have created test project "TestAndroidCalculatorBlackbox" (do we need to have two project one test and one main project, perhaps this could be the reason, cause in Robotium "Getting Started" link they want us to create projects for Notepad),
and added jars robotium-solo-5.0.1.jar,robotium-solo-1.6.0.jar, to get rid of red error lines below solo.functions and jay.way package.
I am attaching the error screenshot: Project tree and error screen shoty AndroidManifest.xml:

我的问题似乎与此处没有什么不同测试运行失败:由于“进程崩溃”,仪器运行失败。在测试多个 Android 活动时,
我遵循了 pdf 中给出步骤。我已经创建了测试项目“TestAndroidCalculatorBlackbox”(我们是否需要有两个项目一个测试和一个主项目,也许这可能是原因,因为在 Robotium“入门”链接中他们希望我们为记事本创建项目),
并添加jars robotium-solo-5.0.1.jar, robotium-solo-1.6.0.jar, 以消除solo.函数和jay.way package.
我附上错误截图: 项目树和错误屏幕截图y 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>

and I have package added in instrumentation list:

我在仪器列表中添加了包:

 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) <<

采纳答案by maszter

  1. Don't attach more than one robotium library. robotium-solo-1.6.0.jar should be removed. It's deprecated and you really shouldn't use it anymore.

  2. Is your target application already installed? It should be installed, if you are going to run tests for it. You can not install it only if your test project has reference to target project.

  3. If you have separate APKs for application and instrumentation you should change package in your manifest. You actually have "com.testcalculator" and target package is the same - they should be different. By the way I don't see sources of application in your project, so application part should be removed.

  4. Your error doesn't say much, it's always good to post stacktrace from LogCat.

  5. Read manuals before you start writing tests:

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

  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

回答by Rowland Mtetezi

For those migrating to or currently using Androidx, this error results from using testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"instead of testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner".

对于迁移到或当前使用 的用户Androidx,此错误是由于使用 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"而不是testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Using the latter resolves the error completely.

使用后者可以完全解决错误。

回答by user3144796

Had this same problem and fixed it by setting up AndroidJUnitRunnerhttps://developer.android.com/training/testing/junit-runner.html

有同样的问题并通过设置https://developer.android.com/training/testing/junit-runner.html修复它AndroidJUnitRunner

回答by Allen

For the developer who hasn't used androidx yet. Seeing the LogCatsolved the issue for me which was deleting these line running in the wrong thread because of RxJava.

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

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

回答by Algorithm and Blues

In my case it was a StrictMode policy violation caused by AndroidJUnitRunner:

就我而言,这是由 AndroidJUnitRunner 引起的 StrictMode 策略违规:

D/StrictMode: StrictMode policy violation: android.os.strictmode.UntaggedSocketViolation: [...]
W/System.err: StrictMode VmPolicy violation with POLICY_DEATH; shutting down.

Disabling the check detectUntaggedSockets() when running an Espresso test fixed it for me. See this questionfor how to check for that.

在运行 Espresso 测试时禁用检查 detectUntaggedSockets() 为我修复了它。请参阅此问题以了解如何检查。