仪器测试在重建后停止工作:未找到测试

时间:2018-01-20 07:03:55

标签: android gradle android-gradle android-testing

我正在尝试使用以下build.gradle为openScale Android应用程序运行androidTest(检测测试):

URL.createObjectURL()

android_app / app / src / androidTest / java / com.health.openscale / DatabaseTest.java下有一个测试文件

我正在使用命令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 } } 来构建和运行测试,并且它第一次正常工作:文件中的两个测试都被执行并通过。

但是现在,如果我更改测试文件(小的更改以触发重建)并再次运行上面的命令,我得到以下输出:

./gradlew --no-daemon --no-build-cache -i connectedDebugAndroidTest

有谁知道为什么重建不起作用?为什么要从构建中删除类?

我已经使用Android工作室中的APK分析器验证了重建后APK中确实缺少DatabaseTest类。

1 个答案:

答案 0 :(得分:0)

似乎将测试用例从.../com.health.openscale/DatabaseTest.java移至.../com/health/openscale/DatabaseTest.java解决了问题。