我的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。
有什么想法吗?
答案 0 :(得分:6)
我有同样的问题,在网上找不到任何东西。答案非常简单:您必须编辑测试的RunConfiguration,使其不是Android测试而是JUnit测试。
所以基本上我做了以下事情:
就是这样。
答案 1 :(得分:5)
我也得到这样的错误,我在build.gradle文件中添加了以下行,如https://google.github.io/android-testing-support-library/docs/espresso/setup/index.html所示,并且它正在运行。我希望它也能帮助你: - )
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
答案 2 :(得分:3)
基本上要检查三件事:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
在该项目/模块的build.gradle的defaultconfig中(如果是子模块)
确保添加了以下测试编译依赖项:
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support:support-annotations:25.2.0'
androidTestCompile 'com.android.support.test:runner:0.5'
确保将测试文件添加到AndroidTest文件夹中,而不仅仅是测试文件夹。
答案 3 :(得分:1)
我从Android测试配置中删除了条目android.support.test.runner.AndroidJUnitRunner
,它开始为我运行测试
答案 4 :(得分:1)
我遇到了同样的问题,发生在我身上的是测试配置错误。
请确保您具有用于测试的正确基本配置,如下图所示:
如果您没有 Android Instrumented Tests 配置,则可以从黄色箭头创建一个。
PS:此外,检查配置所引用的类是否确实 存在并且包名称正确
答案 5 :(得分:0)
我尝试了各种方法,但都没有为我解决问题。我所做的只是简单地将Java测试文件的副本复制到相同的确切文件夹中,但使用不同的名称,然后删除原始文件。
我认为此问题最初是由于将我的测试类从项目测试文件夹移至androidTest
文件夹引起的。