我使用robolectric进行单元测试和仪器测试来测试Android应用程序。我已经启用了jacoco测试覆盖率插件来提供覆盖率报告,但是当至少有一个测试失败时它不会创建。如何在jacoco中忽略失败?
这是我的gradle.build
apply plugin: 'com.android.application'
android {
jacoco {
version = '0.7.3.201502191951'
}
testOptions {
unitTests.returnDefaultValues = true
}
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.nitralabs.m1_mm"
minSdkVersion 12
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
testCoverageEnabled = true
}
}
...
}
dependencies {
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'junit:junit:4.12'
...
}
task jacocoReport << {
ant {
taskdef(name: 'jacocoreport',
classname: 'org.jacoco.ant.ReportTask',
classpath: configurations.jacocoReport.asPath,
ignoreFailures: true, i)
mkdir dir: "${buildDir}/test-coverage-report"
mkdir dir: "${buildDir}/reports/jacoco/test/"
jacocoreport {
executiondata {
fileset dir: "${buildDir}/jacoco"
}
structure(name: "${rootProject.name}") {
classfiles {
fileset(dir: "${buildDir}/intermediates/classes/debug") {
exclude(name: '**/R.class')
exclude(name: '**/R$*.class')
}
}
sourcefiles {
fileset dir: "src/main/java"
fileset dir: 'build/generated/source/buildConfig/debug'
}
}
xml destfile: "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
html destdir: "${buildDir}/test-coverage-report/"
}
}
}
project.afterEvaluate {
def append = "append=true"
def destFile = "destfile=$buildDir/outputs/code-coverage/connected/coverage.ec"
testDebug.jvmArgs "-javaagent:$buildDir/intermediates/jacoco/jacocoagent.jar=$append,$destFile"
createDebugCoverageReport.dependsOn testDebug
}
答案 0 :(得分:0)
这是我忽略失败的单元测试的相关配置
android {
testOptions {
unitTests.all {
setIgnoreFailures(true)
}
}
buildTypes {
debug {
testCoverageEnabled true
}
}
}