0
votes

I'm following these docs

https://docs.gradle.org/4.2.1/userguide/jacoco_plugin.html

In a java app, with the java plugin enabled, I've added this line to enable the jacoco plugin

apply plugin: 'jacoco'

The docs state

If the Java plugin is also applied to your project, a new task named jacocoTestReport is created that depends on the test task

So now when I run

./gradlew build jacocoTestReport

I can see it kicking off the tests as part of build, but we have some failing tests, so the whole test task reports as failed.

The jacoco code coverage report doesn't generate anything.

If I run

./gradlew jacocoTestReport

I get a successful report

This may sound like a daft question, but is the reason the first command, ./gradle1 build jacocoTestReport doesn't generate the report, is because of the failing tests?

Would just ./gradlew build run the jacocoTestReport task if the tests passed?

3

3 Answers

2
votes

I prefer to "teach a man to fish" rather than give a fish. In that spirit I suggest you add the task tree plugin so you can see a visual representation of what's going on for yourself

plugins {
  id "com.dorongold.task-tree" version "1.3.1"
}

You can then try

gradle build taskTree

and

gradle jacocoTestReport taskTree 

And see what's in the task tree for each

0
votes

I've commented out the failing tests and ran ./gradlew build

The remaining tests passed, but no report.

I will have a bash at lance-java's tip for the top, as I do like fishing!

Also going to try ./gradlew build jacocoTestReport

./gradlew build jacocoTestReport is the winner!!

0
votes

It is because the tests failed.

Adding the following will to build.gradle will ensure that coverage is generated regardless:

test.finalizedBy jacocoTestReport