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?
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 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.
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.
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" } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With