Jacoco Plugin Integration With Spring Boot Application


Jacoco:

The Jacoco is a plugin which is implemented in Java. This Jacoco plugin helps developer to generate the test report with code coverage to provide more quality and securable code. Jacoco will generate a report that how many numbers of lines of code executed / not executed.

Download Jacoco plugin:

Downloading and installing the Jacoco plugin is very easy.

Just add a below plugin in the build.gradle file of the parent project ,

    apply plugin: 'jacoco'

Need to add the same command in the build.gradle file of each module to generate  the code coverage report.

Also, add below lines of script in all build.gradle files of all modules,


test {

      

       finalizedBy jacocoTestReport

}

 

jacocoTestReport {

       reports {

              xml.enabled true

       }

    dependsOn test

}

 

jacoco {

    toolVersion = "0.8.5"

}


Snapshot with Jacoco applying to Spring Boot API project,



Execution:

As part of Spring Boot API project, the Jacoco will be execute 2 ways.

    1. Execute Jacoco ( command : gradle test)

    2. Execute Jacoco with SonarQube. Need to run 2 commands

a. Command1: gradle clean build test

b. Command2: gradle sonarqube


1. Execute Jacoco ( command : gradle test):


Once the above command would be run successfully, it  must generate a folder called “build”,

Then double click on the folder “build folder à observe the autogenerated folders like

“classess”,

“generated”,

“jacoco”,

“libs”,

“reports”,

“”resources,

“test-results”,

and “tmp”.




Then double click “reports” folder,

Inside “reports” folder observes 2 folders like “jacoco” and “tests”.




Check code coverage report:

To check the test report,

Open the index.html which is in the directory path ,

reports\jacoco\test\html\index.html


Then the final test code coverage report for Spring Boot API,


Note: The above process is same for all sub modules and generate test report for each module.

To check and generate all modules code coverage report at one place at a time, need to integrate Jacoco plugin with SonarQube in Spring Boot application.

Refer the below SonarQube integration with Spring Boot api blog link,

https://nageswargurram.blogspot.com/2020/12/sonarqube-integration-with-spring-boot.html

            2.  Execute Jacoco with SonarQube:

a.       Command1: (gradle clean build test)


b.       Command2: (gradle sonarqube)


To check the report in the SonarQube launch the SonarQube home page by login with specific login credentials,

All submodules code coverage:


Overall code coverage:



Comments

Popular posts from this blog

SonarQube Integration With Spring Boot Application