gpt4 book ai didi

android - 重建后仪器测试停止工作 : No tests found

转载 作者:行者123 更新时间:2023-11-29 02:33:31 26 4
gpt4 key购买 nike

我正在尝试让 androidTest(仪器测试)为 openScale 工作使用以下 build.gradle 的 Android 应用程序:

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,
...

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

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

最佳答案

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

关于android - 重建后仪器测试停止工作 : No tests found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48353564/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com