Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse - Java - Gradle is skipping jacocoTestReport

Project structure:

    src/main/java
    src/main/resources
    src/test/java

Gradle version : 2.2.1

Here is my build.gradle

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'jacoco'
    version = '1.0'
   sourceCompatibility = 1.7
   targetCompatibility = 1.7

 test {
    include 'src/test/java'
    finalizedBy jacocoTestReport

   }

  jacoco {
    toolVersion = "0.7.6.201602180812"

  }

 jacocoTestReport {
  group = "Reporting"
  description = "Generate Jacoco coverage reports after running tests."
  additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
  reports {
      xml.enabled false
      csv.enabled false
      html.destination "${buildDir}/reports/jacoco/html"
}
}

when I run gradle task as "test jacocoTestReport", I am getting the below results

  :compileJava UP-TO-DATE
  :processResources UP-TO-DATE
  :classes UP-TO-DATE
  :compileTestJava UP-TO-DATE
  :processTestResources UP-TO-DATE
  :testClasses UP-TO-DATE
  :test UP-TO-DATE
  :jacocoTestReport SKIPPED

can someone please suggest what should be added to execute jacoco test report.

Thanks.

like image 594
Kishore Avatar asked Sep 21 '16 07:09

Kishore


4 Answers

Unfortunately, none of these answers worked for me.
For Spring 2.5 Users, who got stuck with it for hours -just like myself.

I had a similar issue.
I was not having the exec file generated.
And because of that , I found that the jacocoTestReport was simply "skipped".

I got it fixed by adding :

test {
  useJUnitPlatform()
  finalizedBy jacocoTestReport // report is always generated after tests run
}

That's because I'm using Junit5 with spring boot 2.X - Gradle 7.1
And as of today Junit5 is not invoked by default in the test task.

like image 195
M. Amer Avatar answered Nov 02 '22 17:11

M. Amer


You can force it to run with:

jacocoTestReport { onlyIf = { true } }

This will probably give an error (there's a reason it didnt run in the first place), but the error should give more information.

like image 37
john ktejik Avatar answered Nov 02 '22 15:11

john ktejik


The task will only run if coverage data is available. You can make sure of that by also running the test task.

Source - Running jacocoReport

like image 33
ericdemo07 Avatar answered Nov 02 '22 17:11

ericdemo07


I was able to generate the code coverage results with the following set up.

 apply plugin: 'jacoco'
 jacocoTestReport {
   reports {
   xml.enabled false
   csv.enabled false
   html.destination "${buildDir}/jacocoHtml"
 }
}
like image 4
Kishore Avatar answered Nov 02 '22 16:11

Kishore