我們有一個多模塊應用程序。我們有3個圖書館項目和1個啓動項目。多模塊應用的Android測試覆蓋率報告
模塊1(Libraray) 模塊2(Libraray)取決於模塊1 單詞數(Libraray)取決於模塊1
啓動(沒有任何的源代碼,它只是對所有LIB的啓動)取決於模塊1和模塊2 。
在module1中,我們使用facade模式來訪問模塊2和模塊3的類。由於我們需要在啓動項目中編寫所有測試用例,因爲我們可以訪問啓動項目中的所有類,因此我們可以訪問所有類,並且測試用例不會由於NoClassDefException而失敗。
當我們在Launch項目中編寫測試用例時,我們能夠運行測試用例,我們得到的執行報告爲100%,它創建了一個包含測試用例所有細節的index.html文件,但是當我嘗試生成覆蓋率報告,然後不顯示覆蓋率報告的任何數據。以下是我的gradle文件。
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 22
buildToolsVersion "23.0.2"`
defaultConfig {
applicationId "com.test.mobile"
minSdkVersion 14
targetSdkVersion 17
multiDexEnabled true
testApplicationId "com.test.mobile.test"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
repositories {
mavenCentral()
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
debug{
testCoverageEnabled true
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4096M"
jumboMode = true
incremental false
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex'
dx.additionalParameters += "--main-dex-list=$projectDir\\multidex-main-dex-list.txt".toString()
}
}}
dependencies {
compile project(':module2')
compile project(':module3')
compile "com.android.support.test.espresso:espresso-idling-resource:2.2.1"
// Dependencies for local unit tests
testCompile "junit:junit:4.12" exclude group: 'com.android.support', module: 'support-annotations'
testCompile "org.mockito:mockito-all:1.10.19" exclude group: 'com.android.support', module: 'support-annotations'
testCompile "org.hamcrest:hamcrest-all:1.3" exclude group: 'com.android.support', module: 'support-annotations'
testCompile "org.powermock:powermock-module-junit4:1.6.2" exclude group: 'com.android.support', module: 'support-annotations'
testCompile "org.powermock:powermock-api-mockito:1.6.2" exclude group: 'com.android.support', module: 'support-annotations'
// Android Testing Support Library's runner and rules
androidTestCompile "com.android.support.test:runner:0.4.1" exclude group: 'com.android.support', module: 'support-annotations'
androidTestCompile "com.android.support.test:rules:0.4.1" exclude group: 'com.android.support', module: 'support-annotations'
// Espresso UI Testing dependencies.
androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.1" exclude group: 'com.google.code.findbugs' exclude group: 'javax.annotation' exclude group: 'com.android.support', module: 'support-annotations' exclude module: 'javax.annotation-api'
androidTestCompile "com.android.support.test.espresso:espresso-contrib:2.2.1" exclude group: 'com.google.code.findbugs' exclude group: 'javax.annotation' exclude group: 'com.android.support', module: 'support-annotations' exclude module: 'javax.annotation-api' exclude group: 'com.android.support', module: 'support-v4'
androidTestCompile "com.android.support.test.espresso:espresso-intents:2.2.1" exclude group: 'com.google.code.findbugs' exclude group: 'javax.annotation' exclude group: 'com.android.support', module: 'support-annotations' exclude module: 'javax.annotation-api'}
task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') { def projects = new ArrayList() subprojects.each { prj -> projects.add(prj) }
reports {
xml.enabled = true
html.enabled = true
}
jacocoClasspath = configurations['androidJacocoAnt']
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
/*sourceDirectories = generateSourceFiles(projects)
classDirectories = generateClassDirs(projects)*/
executionData = files(["${buildDir}/jacoco/testDebugUnitTest.exec",
"${buildDir}/outputs/code-coverage/connected/coverage.ec"
])}
你在'build.gradle'圖書館類似的變化? –
其他下面是lib項目build.gradle中的一個。 'android {{{0} {編譯斯德哥爾摩22 buildToolsVersion「23.0。2" defaultConfig { 的minSdkVersion 14 targetSdkVersion 17 multiDexEnabled真 } buildTypes { 釋放{ minifyEnabled假 proguardFiles getDefaultProguardFile( 'proguard的-android.txt'), 'proguard的-project.txt' } } }' 測試用例信息在lib項目中不可用 –