我正在尝试在Android 6.0(API 23)设备(模拟器和物理设备)上运行gradle Task :app:connectedDevDebugAndroidTest
,并遇到错误:
> Task :app:processDevDebugGoogleServices
Parsing json file: /Users/<name>/Projects/mobile-app-android/app/google-services.json
Starting 0 tests on Nexus_4_API_23(AVD) - 6.0
Tests on Nexus_4_API_23(AVD) - 6.0 failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'
com.android.builder.testing.ConnectedDevice > No tests found.[Nexus_4_API_23(AVD) - 6.0] 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).
> Task :app:connectedDevDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:connectedDevDebugAndroidTest'.
> There were failing tests. See the report at: file:///Users/<name>/Projects/mobile-app-android/app/build/reports/androidTests/connected/flavors/DEV/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
我试图找出问题的不同原因。只有在终端中运行./gradlew connectedDevDebugAndroidTest
(检测测试)时,才会为Android 6.0弹出此错误。我最近在app/build.gradle
中升级了一些测试库:
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.7.1'
testImplementation 'org.robolectric:shadows-support-v4:3.0'
testImplementation ('com.squareup.assertj:assertj-android:1.1.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}
testImplementation 'org.mockito:mockito-core:2.16.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation ('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
androidTestImplementation 'com.google.guava:guava:23.0' // Needed for EspressoTestRule
androidTestImplementation 'org.mockito:mockito-android:2.16.0'
androidTestImplementation 'com.github.fabioCollini:DaggerMock:0.8.4'
androidTestImplementation 'com.github.andrzejchm.RESTMock:android:0.1.3'
androidTestImplementation('com.squareup.okhttp3:mockwebserver:3.8.1') {
exclude module: 'bcprov-jdk15on'
exclude module: 'okhttp' // See: https://github.com/square/okhttp/issues/679
}
androidTestImplementation 'org.skyscreamer:jsonassert:1.4.0'
我怀疑最新版本的mockito
或espresso
中的某些内容已被破坏,但我不确定。
答案 0 :(得分:0)
我偶尔会遇到特定设备的“未找到测试”错误,并清理项目,关闭Android Studio,然后重新启动它似乎可以解决问题。