0

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 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @lance-java I will give that a go to further my understanding
oooh, that's nice, will definitely use that from now on
0

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!!

1 Comment

You could also add something like check.dependsOn jacocoTestReport to your build.gradle. This would permanently wire the jacocoTestReport task to the "check" lifecycle task (which as you've seen is called by the "build" lifecycle task)
0

It is because the tests failed.

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

test.finalizedBy jacocoTestReport

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.