Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle jacocoTestReport is not working?

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

The build.gradle 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"     } } 

I then ran

gradle test jacocoTestReport 

Where after only the file test.exec is generated in build/reports folder.

Other than that nothing happens.

How can I get the HTML report?

like image 874
prashanth-g Avatar asked Mar 17 '15 11:03

prashanth-g


People also ask

What is jacocoTestReport?

JaCoCo Report configurationThe JacocoReport task can be used to generate code coverage reports in different formats. It implements the standard Gradle type Reporting and exposes a report container of type JacocoReportsContainer. Example 4. Configuring test task. build.gradle.

Why is JaCoCo not showing coverage for some classes?

Why does the coverage report not show highlighted source code? Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports: Class files must be compiled with debug information to contain line numbers. Source files must be properly supplied at report generation time.


2 Answers

You don't have 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

You can find the test report in ./build/reports/jacoco/test directory.

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

like image 58
Tyler Liu Avatar answered Sep 20 '22 18:09

Tyler Liu


Following helped . its in samples/testing/jacaco of 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"     } } 
like image 39
prashanth-g Avatar answered Sep 19 '22 18:09

prashanth-g