使用jacoco与Gradle

时间:2016-03-28 20:56:18

标签: gradle jacoco gradle-plugin

如果测试失败,Jacoco无法生成代码覆盖率报告。

以下是我的gradle文件的相关部分:

task unitTest(type: Test) {
    forkEvery = 1
    jvmArgs = ['-Djava.net.preferIPv4Stack=true']
    testClassesDir = sourceSets.unitTest.output.classesDir
    classpath = sourceSets.unitTest.runtimeClasspath
    exclude '**/**TestBase.*'
    outputs.upToDateWhen { false }
    ignoreFailures = true
    finalizedBy jacocoTestReport
}

task functionalTest(type: Test) {
    forkEvery = 1
    jvmArgs = ['-Djava.net.preferIPv4Stack=true']
    testClassesDir = sourceSets.functionalTest.output.classesDir
    classpath = sourceSets.functionalTest.runtimeClasspath
    exclude '**/**TestBase.*'
    outputs.upToDateWhen { false }  
}


jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."

    additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/reports/jacoco/html"
    }   
    executionData = files('build/jacoco/test.exec')
}

即使我已指定" ignoreFailures = true",但在测试运行后没有代码覆盖率报告。

There were failing tests. See the report at: file:///unitTest/index.html
:MYModule:jacocoTestReport SKIPPED

BUILD SUCCESSFUL

Total time: 41 mins 34.018 secs

1 个答案:

答案 0 :(得分:1)

问题是executionData指向错误的“test.exec”。它应该是“unitTest.exec”,以正在执行的测试任务命名。