How To Get Code Coverage for only specific classes in Gradle project using Jacoco

1.5k Views Asked by At

Here ProjectA is gradle project and each packages(Service1, Service2, Service3) under the ProjectA acts like a microservice.

ProjectA 
 - Service1
    - ClassA
    - ClassB
    build.gradle
 - Service2
    - ClassC
    - ClassD
     build.gradle
 - Service3
     -ClassE
     - Class F
    build.gradle 

build.gradle (for entire ProjectA)

a. Now i wanted to have a jacoco coverage only for specific classes inside each package(say ClassA, ClassD and ClassF) in build.gradle(ProjectA) and generate a html coverage report for it.

Can someone help me in this?

b. Also Usually the report gets generated in target/site/jacoco/index.html but is it possible to specify our own path where the report needs to be generated?

Can someone guide me how we can generate reports for specific classes in our own predefined path?

Thanks in advance.

1

There are 1 best solutions below

0
On

Have a look at the Gradle Jacoco plugin documentation, you will see that:

  • you can set the reports directory with jacoco.reportsDir
  • you can configure includes and excludes on the Jacoco extension available at the task level. So test.jacoco.includes for the default test task.