【问题标题】:Android test project is crashing with error "Test run failed: Instrumentation run failed due to 'Process crashed.'"Android 测试项目因错误“测试运行失败:仪器运行因‘进程崩溃’而失败。”而崩溃
【发布时间】:2014-03-03 12:50:35
【问题描述】:

我的问题似乎与这里的 Test run failed: Instrumentation run failed due to 'Process crashed.' when testing multiple Android activity 略有不同
我已按照in the pdf 给出的步骤进行操作。我已经创建了测试项目“TestAndroidCalculatorBlackbox”(我们是否需要有两个项目一个测试和一个主项目,也许这可能是原因,因为在 Robotium“入门”链接中他们希望我们为记事本创建项目),
并添加了罐子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>

我已经在检测列表中添加了包:

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

【问题讨论】:

    标签: android automation robotium


    【解决方案1】:

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

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

    【讨论】:

    • 太棒了!非常感谢您的评论。为我工作!
    • 昨天我离开办公室思考这个问题。今天早上你为我解决了!非常感谢罗兰!
    • 优秀。谢谢你。 Android真的应该有更清晰的错误!在我找到你的评论之前,我刚刚失去了一个小时的工作。
    【解决方案2】:
    1. 不要附加多个robotium 库。应该删除 robots-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 和应用程序标签)
    • 找不到什么类?使用 LogCat
    • 我的 LogCat 不打印任何东西
    【解决方案3】:

    遇到同样的问题并通过设置AndroidJUnitRunner https://developer.android.com/training/testing/junit-runner.html 解决了它

    【讨论】:

      【解决方案4】:

      给还没用过androidx的开发者。看到 LogCat 解决了我的问题,因为 RxJava 删除了在错误线程中运行的这些行。

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

      【讨论】:

        【解决方案5】:

        在我的情况下,这是由 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 了解如何检查。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-11-18
          • 1970-01-01
          • 1970-01-01
          • 2015-01-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多