我试图生成Jacoco代码覆盖率报告。 我已经使用AndroidTestCase为我的测试类。Jacoco代码覆盖在Android Studio中
我一直在使用testCoverageEnabled真实,使用默认的Android -Studio默认jacoco, ./gradlew connectedCheck或createDebugCoverageReport 创建全成的百分比/失败测试案例,但没有覆盖报告发现。
然后我尝试了jacoco {toolVersion“0.7.1.201405082137”}和任务jacocoTestReport(类型:JacocoReport,dependsOn:“testDebug”)。我试图用各种任务来改变dependsOn值。该报告显示0(零)测试覆盖率,这是不可能的,因为至少有一半的类都经过测试。
我跟随在过去几天的堆栈溢出的各种公认的答案。结果是消极的。
我gradle这个文件:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "test.gradle.com.myapplicationtestgradle"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(
'proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
jacoco {
version "0.7.1.201405082137"
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
jacoco {
toolVersion "0.7.1.201405082137"
}
task jacocoTestReport(type:JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
// exclude auto-generated classes and tests
def fileFilter = ['**/R.class', '**/R$*.class',
'**/BuildConfig.*', '**/Manifest*.*',
'android/**/*.*']
def debugTree = fileTree(dir:
"${project.buildDir}/intermediates/classes/debug",
excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
additionalSourceDirs = files([
"${buildDir}/generated/source/buildConfig/debug",
"${buildDir}/generated/source/r/debug"
])
executionData = fileTree(dir: project.projectDir, includes:
['**/*.exec', '**/*.ec'])
reports {
xml.enabled = true
xml.destination = "${buildDir}/jacocoTestReport.xml"
csv.enabled = false
html.enabled = true
html.destination = "${buildDir}/reports/jacoco"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
}
只是引用什么似乎是获得任何类型的覆盖报告生成的规范方法,请参阅[this](http://stackoverflow.com/q/23795595/269300)这样的问题 - 任何人谁在获取'createDebugCoverageReport'时遇到问题。 – 2015-03-19 20:11:33
我已经看到了接受的答案。我认为。你对仪器测试和单元测试都是正确的。我确实需要看看(testDebug.jvmArgs)。非常感谢你解释一些有用的信息。 – user1365169 2015-03-20 15:29:28
这似乎并没有为我合并这两份报告。它只包括来自android测试的覆盖,而不是单元测试。我使用多种口味,但是我相应地更改了'project.afterEvaluate'。任何想法? – 2015-04-09 07:58:18