Android 重建后仪器测试停止工作:未找到任何测试
我正在尝试使用以下build.gradle使androidTest(instrumentation tests)适用于Android应用程序:Android 重建后仪器测试停止工作:未找到任何测试,android,gradle,android-gradle-plugin,android-testing,Android,Gradle,Android Gradle Plugin,Android Testing,我正在尝试使用以下build.gradle使androidTest(instrumentation tests)适用于Android应用程序: apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId "com.health.openscale" testApplicationId "com.healt
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.health.openscale"
testApplicationId "com.health.openscale.test"
minSdkVersion 18
targetSdkVersion 22 // don't set target sdk > 22 otherwise bluetooth le discovery need permission to ACCESS_COARSE_LOCATION
versionCode 22
versionName "1.7 (beta)"
javaCompileOptions {
annotationProcessorOptions { arguments = ["room.schemaLocation":"$projectDir/schemas".toString()] }
}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
lintOptions {
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
ext {
supportLibVersion = '27.0.2'
}
dependencies {
implementation "com.android.support:design:${supportLibVersion}"
implementation "com.android.support:support-v4:${supportLibVersion}"
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
// HelloCharts
implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
// Simple CSV
implementation 'com.j256.simplecsv:simplecsv:2.2'
// CustomActivityOnCrash
implementation 'cat.ereza:customactivityoncrash:2.2.0'
// Room
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
androidTestImplementation 'android.arch.persistence.room:testing:1.0.0'
// Local unit tests
testImplementation 'junit:junit:4.12'
// Instrumented unit tests
androidTestImplementation "com.android.support:support-annotations:${supportLibVersion}"
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
android_app/app/src/androidTest/java/com.health.openscale/DatabaseTest.java下有一个测试文件
我正在使用命令/gradlew--no daemon--no build cache--I connectedDebugAndroidTest
来构建和运行测试,第一次它工作正常:文件中的两个测试都被执行并通过
但是现在,如果我更改测试文件(触发重建的小更改)并再次运行上述命令,我将获得以下输出:
...
Putting task artifact state for task ':app:compileDebugAndroidTestJavaWithJavac' into context took 0.0 secs.
file or directory '/<path>/android_app/app/src/androidTestDebug/java', not found
Executing task ':app:compileDebugAndroidTestJavaWithJavac' (up-to-date check took 0.007 secs) due to:
Input property 'source' file /<path>/android_app/app/src/androidTest/java/com.health.openscale/DatabaseTest.java has changed.
Compiling with source level 1.7 and target level 1.7.
...
Putting task artifact state for task ':app:transformClassesWithDexBuilderForDebugAndroidTest' into context took 0.0 secs.
Executing task ':app:transformClassesWithDexBuilderForDebugAndroidTest' (up-to-date check took 0.024 secs) due to:
Input property '$3' file /<path>/android_app/app/build/intermediates/classes/androidTest/debug/com/health/openscale/DatabaseTest.class has been removed.
Transform inputs calculations based on following changes
/<path>/android_app/app/build/intermediates/classes/androidTest/debug/com/health/openscale/DatabaseTest.class:REMOVED
...
Starting 0 tests on Nexus_5X_API_26(AVD) - 8.0.0
[XmlResultReporter]: XML test result file generated at /<path>/android_app/app/build/outputs/androidTest-results/connected/TEST-Nexus_5X_API_26(AVD) - 8.0.0-app-.xml. Total tests 0,
com.android.builder.testing.ConnectedDevice > No tests found.[Nexus_5X_API_26(AVD) - 8.0.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).
[XmlResultReporter]: XML test result file generated at /<path>/android_app/app/build/outputs/androidTest-results/connected/TEST-Nexus_5X_API_26(AVD) - 8.0.0-app-.xml. Total tests 1, failure 1,
...
。。。
将任务“:app:compiledBugandroidTestJavaWithJavaC”的任务工件状态放入上下文需要0.0秒。
未找到文件或目录“//android\u app/app/src/androidTestDebug/java”
正在执行任务“:app:compiledBugandroidTestJavaWithJavaC”(最新检查耗时0.007秒),原因是:
输入属性“source”文件//android_app/app/src/androidTest/java/com.health.openscale/DatabaseTest.java已更改。
使用源级别1.7和目标级别1.7编译。
...
将任务“:app:transformClassesWithDexBuilderForDebugAndroidTest”的任务工件状态放入上下文需要0.0秒。
正在执行任务“:app:transformClassesWithDexBuilderForDebugAndroidTest”(最新检查耗时0.024秒),原因是:
已删除输入属性“$3”文件//android_app/app/build/intermediates/classes/androidTest/debug/com/health/openscale/DatabaseTest.class。
基于以下更改转换输入计算
//android_app/app/build/intermediates/classes/androidTest/debug/com/health/openscale/DatabaseTest.class:已删除
...
在Nexus_5X_API_26(AVD)-8.0.0上启动0测试
[XmlResultReporter]:在//android_app/app/build/outputs/androidTest results/connected/test-Nexus_5X_API_26(AVD)-8.0.0-app-.XML生成的XML测试结果文件。测试总数0,
com.android.builder.testing.ConnectedDevice>未找到任何测试。[Nexus_5X_API_26(AVD)-8.0.0]失败
没有发现任何测试。这通常意味着您的测试类不是您的测试运行程序所期望的形式(例如,不从TestCase继承或缺少@test注释)。
[XmlResultReporter]:在//android_app/app/build/outputs/androidTest results/connected/test-Nexus_5X_API_26(AVD)-8.0.0-app-.XML生成的XML测试结果文件。总试验1,故障1,
...
有人知道重建失败的原因吗?为什么要从构建中删除该类
我已经通过Android studio中的APK analyzer验证了DatabaseTest类在重建后确实从APK中丢失。似乎将测试用例从
../com.health.openscale/DatabaseTest.java
移动到../com/health/openscale/DatabaseTest.java
解决了这个问题