我正在尝试将我的项目更新为最近发布的 Android 测试支持库版本 1.0.0。但是,如果我添加 assertj-core
依赖项,Gradle 检测的测试任务开始失败,并显示“未找到测试”消息。不过,我可以从 IDE 成功运行单个测试。
很容易重现问题:
- 使用空 Activity 从 Android Studio 3 创建新项目。
- 添加
assertj-core
依赖。 - 从命令行
./gradlew connectedDebugAndroidTest
运行仪器测试。
Gradle 脚本。
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:26.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.0'
androidTestImplementation group: "org.assertj", name: "assertj-core", version: "2.8.0"
}
控制台输出。
com.android.builder.testing.ConnectedDevice > No tests found.
[Nexus_4_API_25(AVD) - 7.1.1] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
如果将 com.android.support.test:runner
降级到以前的版本 0.5,测试会成功运行。
最佳答案
除非其中至少一个名称以 test
开头,否则我的测试用例不会被选中。
我创建了一个虚拟忽略的测试用例:
@Test
fun testDummy() {
Assume.assumeTrue(false)
}
关于android - AndroidJUnitRunner 1.0.0 和 AssertJ 的仪器化测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45402645/