Gradle jacocoTestReport not working?

I tried to get code coverage in a spring - gradle project using the gradle jacoco plugin.

The build.gradle file contains the following

apply plugin: "jacoco" jacoco { toolVersion = "0.7.1.201405082137" reportsDir = file("$buildDir/customJacocoReportDir") } jacocoTestReport { reports { xml.enabled false csv.enabled false html.destination "${buildDir}/jacocoHtml" } } 

Then i ran

 gradle test jacocoTestReport 

When, after creating the build / reports file, the test.exec file is created.

Other than this, nothing happens.

How can I get an HTML report?

+16
build.gradle gradle
source share
2 answers

The following helped. its in samples / testing / jacaco from gradle-2.3-all.zip from https://gradle.org/releases/

 apply plugin: "java" apply plugin: "jacoco" jacoco { toolVersion = "0.7.1.201405082137" reportsDir = file("$buildDir/customJacocoReportDir") } repositories { mavenCentral() } dependencies { testCompile "junit:junit:4.+" } test { jacoco { append = false destinationFile = file("$buildDir/jacoco/jacocoTest.exec") classDumpFile = file("$buildDir/jacoco/classpathdumps") } } jacocoTestReport { reports { xml.enabled false csv.enabled false html.destination "${buildDir}/jacocoHtml" } } 
+11
source share

You do not need to configure reportsDir/destinationFile

Because jacoco has default values ​​for them.

build.gradle:

 plugins { id 'java' id 'jacoco' } jacocoTestReport { reports { xml.enabled true html.enabled true csv.enabled true } } repositories { jcenter() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' } 

Run gradle test jacocoTestReport

Test report can be found in the directory ./build/reports/jacoco/test .

The HTML output is in the ./build/reports/jacoco/test/html directory.

+6
source share

All Articles