gpt4 book ai didi

Android Studio 单元测试 : unable to find instrumentation OR class not found ex

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:13 25 4
gpt4 key购买 nike

我的 Android 工作室中有一个测试套件,它具有以下目录结构:

-MainProject
-src
--com
--tests
--java.xx.xxx.xx.test

在我的 AndroidManifest 中,我有以下内容:

<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="tests.java.xxx.xxx.xxx.test" />

当我使用 ./gradlew connectedInstrumentTest 从命令行运行测试时,我只得到:

Tests on Nexus 5 - 4.4.2 failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'

当我从 Android Studio 中运行测试时,我得到:

Running tests
Test running startedTest running failed: Unable to find instrumentation info for: ComponentInfo{tests.xxx.xxx.xxx.xxx.test/android.test.InstrumentationTestRunner}
Empty test suite.

我还在 build.gradle 文件的 defaultConfig 中指定了 testPackageName。我在 Ubuntu 12.0.4 上运行 Android Studio 0.4.6。

有什么想法吗?

最佳答案

我遇到了同样的问题,在网上找不到任何东西。答案非常简单:您必须编辑测试的 RunConfiguration,使其不是 Android 测试而是 JUnit 测试。

所以基本上我做了以下事情:

  1. 点击“编辑配置”
  2. 点击“添加新配置”并选择 JUnit
  3. 在 Test kind 处插入了名称和并选择了“All in package”。

就是这样。

关于Android Studio 单元测试 : unable to find instrumentation OR class not found ex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22106891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com