我将testCoverageEnabled = true
添加到debug
构建类型后,我的检测测试开始失败并显示消息Started running tests
Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'
Empty test suite.
testCoverageEnabled = false
一切正常有什么奇怪的。
这是我的build.gradle
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.21.7'
classpath 'io.realm:realm-gradle-plugin:3.0.0'
// https://github.com/JakeWharton/hugo
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
// https://github.com/stanfy/spoon-gradle-plugin
classpath('com.stanfy.spoon:spoon-gradle-plugin:1.2.0') {
exclude module: 'guava'
}
classpath 'com.google.guava:guava:20.0'
// https://github.com/zsoltk/paperwork
classpath 'hu.supercluster:paperwork-plugin:1.2.7'
// https://github.com/android10/frodo
classpath "com.fernandocejas.frodo:frodo-plugin:0.8.3"
}
}
apply plugin: 'com.android.application'
apply plugin: 'findbugs'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
apply plugin: 'spoon'
apply plugin: 'android-command'
apply plugin: 'com.jakewharton.hugo'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'hu.supercluster.paperwork'
apply plugin: 'permission'
apply plugin: 'com.fernandocejas.frodo'
apply plugin: "me.tatarka.retrolambda"
apply from: './jacoco.gradle'
int minSdk = project.hasProperty('minSdk') ? minSdk.toInteger() : 18 //Android 4.3 (Look into gradle.properties for actual value)
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' }
flatDir {
dirs 'libs'
}
}
paperwork {
set = [
gitSha : gitSha(),
buildDate: buildTime("dd-MM-yyyy HH:mm:00 z", "UTC"),
]
}
frodo {
enabled = true
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
dataBinding {
enabled true
}
defaultConfig {
applicationId "..."
minSdkVersion minSdk
targetSdkVersion 24
vectorDrawables.useSupportLibrary = true
versionCode 12
versionName "1.4"
testInstrumentationRunner "com.mobile.TestAppAndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
debug {
applicationIdSuffix ".debug"
minifyEnabled false
testCoverageEnabled = true
debuggable = true;
ext.enableCrashlytics = false
buildConfigField "boolean", "DISABLE_CRASHLITYCS", "true"
}
rc {
initWith(release)
applicationIdSuffix ".rc"
versionNameSuffix "-rc"
debuggable true
buildConfigField "boolean", "DISABLE_CRASHLITYCS", "false"
ext.enableCrashlytics = true
signingConfig signingConfigs.release
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testCoverageEnabled false
buildConfigField "boolean", "DISABLE_CRASHLITYCS", "false"
ext.enableCrashlytics = true
signingConfig signingConfigs.release
}
}
productFlavors {
internal {
applicationIdSuffix = ".internal"
}
production {
}
}
// Remove internalRelease as it's not needed.
android.variantFilter { variant ->
if (variant.buildType.name.equals('release')
&& variant.getFlavors().get(0).name.equals('internal')) {
variant.setIgnore(true)
} else if (variant.buildType.name.equals('rc')
&& variant.getFlavors().get(0).name.equals('internal')) {
variant.setIgnore(true)
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
// returnDefaultValues = true was added to avoid an error while calling Application.onCreate in Unit test:
// http://tools.android.com/tech-docs/unit-testing-support#TOC-Method-...-not-mocked.-
returnDefaultValues = true
all {
testLogging {
exceptionFormat = 'full'
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
}
}
packagingOptions {
// excluding to avoid DuplicateFileException
exclude 'META-INF/maven/com.google.dagger/dagger/pom.properties'
exclude 'META-INF/maven/com.google.dagger/dagger/pom.xml'
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
lintOptions {
abortOnError false
}
sourceSets {
main.res.srcDirs = [
'src/main/res',
// component resources
'src/main/res_components/customization',
'src/main/res_components/daily',
'src/main/res_components/external',
'src/main/res_components/leaflet',
'src/main/res_components/more',
'src/main/res_components/onboarding',
'src/main/res_components/search',
'src/main/res_components/scanner',
'src/main/res_components/treatments',
'src/main/res_components/treatment',
'src/main/res_components/treatment_plan',
'src/main/res_components/wizard'
]
}
}
dependencies {
//tooltips
compile project(':calendar')
compile project(':tooltips')
// dependency injection
compile 'com.google.dagger:dagger:2.7'
annotationProcessor 'com.google.dagger:dagger-compiler:2.7'
provided 'org.glassfish:javax.annotation:10.0-b28'
// icepick
compile 'frankiesardo:icepick:3.2.0'
annotationProcessor 'frankiesardo:icepick-processor:3.2.0'
// reactive java
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.uphyca:stetho_realm:2.0.0'
// rest client
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.6.0'
// material design support libraries
compile 'com.android.support:support-annotations:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:transition:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
// Barcode scanning
// You can add javadoc it is located in app/libs/docs
compile(name: 'CortexDecoderLibrary', ext: 'aar')
// multidex
compile 'com.android.support:multidex:1.0.1'
// permissions
compile 'com.github.hotchemi:permissionsdispatcher:2.1.3'
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.1.3'
// tools
provided 'org.projectlombok:lombok:1.16.14'
annotationProcessor "org.projectlombok:lombok:1.16.14"
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.jakewharton.timber:timber:4.1.2'
compile 'hu.supercluster:paperwork:1.2.7'
// time --- JSR-310 backport --- https://github.com/JakeWharton/ThreeTenABP
compile 'com.jakewharton.threetenabp:threetenabp:1.0.3'
// graphics
compile 'com.squareup.picasso:picasso:2.5.2'
// UI
compile('com.mikepenz:fastadapter:2.1.6@aar') {
transitive = true
}
compile 'com.mikepenz:fastadapter-commons:2.1.0@aar'
compile('com.mikepenz:materialdrawer:5.8.1@aar') {
transitive = true
}
compile('com.aurelhubert:ahbottomnavigation:2.0.2') {
exclude module: 'design'
}
compile 'com.github.lsjwzh.RecyclerViewPager:lib:v1.1.0'
// number picker
compile 'com.shawnlin:number-picker:2.0.1'
// date picker
compile 'com.code-troopers.betterpickers:library:3.0.1'
// XML schema validation TODO replace with something smaller
compile files('libs/xerces-for-android.jar')
// tracking
compile "com.mixpanel.android:mixpanel-android:4.9.2"
// fabric
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
transitive = true;
}
//debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
rcCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
// Dependencies for unit test
testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.7'
testCompile 'com.google.dagger:dagger:2.7'
testCompile 'com.github.fabioCollini:DaggerMock:0.6.1'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.powermock:powermock-api-mockito:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.6.5'
testCompile "org.powermock:powermock-module-junit4-rule:1.6.5"
testCompile "org.powermock:powermock-classloading-xstream:1.6.5"
testCompile 'com.google.truth:truth:0.28'
testCompile 'com.google.guava:guava:20.0'
// fallback to standard JVM time backport for unit testing
testCompile 'org.threeten:threetenbp:1.3.2'
// Barcode scanning
// You can add javadoc it is located in app/libs/docs
testCompile(name: 'CortexDecoderLibrary', ext: 'aar')
// Robolectric
testCompile 'org.robolectric:robolectric:3.1.2'
testCompile 'org.robolectric:shadows-core:3.1.2'
testCompile 'org.robolectric:shadows-multidex:3.1.2'
testCompile 'org.robolectric:shadows-support-v4:3.1.2'
// workaround for missing opengl
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
// Network
testCompile 'com.squareup.okhttp3:mockwebserver:3.6.0'
// Android Testing Support Library's runner and rules
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.7'
androidTestCompile 'com.google.dagger:dagger:2.7'
// Dependencies for Android unit tests
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
// --- fixed 1.4 version | allows using MockAnnotations again ---
// https://github.com/crittercism/dexmaker/pull/24
androidTestCompile "com.github.crittercism.dexmaker:dexmaker-parent:f8e7c23e4172af8767758c99c9165dd2bd4f0e7f"
androidTestCompile("com.github.crittercism.dexmaker:dexmaker-mockito:f8e7c23e4172af8767758c99c9165dd2bd4f0e7f") {
exclude group: 'mockito'
}
androidTestCompile "com.github.crittercism.dexmaker:dexmaker-dx:f8e7c23e4172af8767758c99c9165dd2bd4f0e7f"
androidTestCompile "com.github.crittercism.dexmaker:dexmaker:f8e7c23e4172af8767758c99c9165dd2bd4f0e7f"
// ---
// Espresso Ui Testing
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'javax.inject'
})
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'
// Resolve conflicts between main and test APK:
androidTestCompile 'com.android.support:support-annotations:25.2.0'
androidTestCompile 'com.android.support:design:25.2.0'
androidTestCompile 'com.android.support:appcompat-v7:25.2.0'
androidTestCompile 'com.android.support:cardview-v7:25.2.0'
androidTestCompile 'com.android.support:recyclerview-v7:25.2.0'
}
configurations {
androidTestCompile.exclude group: 'com.android.support', module: 'support-v4'
}
答案 0 :(得分:0)
尝试在app/build.gradle
sourceSets {
main {
assets.srcDirs = ['assets', 'src/main/assets', 'src/main/assets/fonts']
java.srcDirs = ['src/main/java', 'src/instrumentTest', 'src/instrumentTest/java', 'src/test/java']
}
test {
java.srcDirs = ['src/test/java', 'src/test/java/']
resources.srcDirs = ['src/test/resources']
}
}