简体   繁体   中英

Ignore failing test in jacoco test coverage

I'm using robolectric for unit tests and instrumentation tests for testing an android application. I've enabled jacoco test coverage plugin for providing coverage report, but it doesn't create when there is at least one failed test. How can failures be ignored in jacoco?

Here is my 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
    } 

This is my relevant config to ignore failing unit tests

android {

 testOptions {
    unitTests.all {
        setIgnoreFailures(true)
    }
}

buildTypes {
    debug {
        testCoverageEnabled true
        }
    }
}       

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM