Skip to content

This is an example of multi modular maven project with jacoco coverage for unit, integration and functional testing and generating a merged final report in jacoco.

License

Notifications You must be signed in to change notification settings

Nykredit/jacoco-multi-module-sample

 
 

Repository files navigation

Jacoco coverage for Multi Module Maven Project

Overview

A sample multi-modular maven project demonstrating how to met coverage for unit, integration and/or functional testing withing different modules. The test results is aggregated by Jacoco plugin and a merged code coverage report is being generated. The detailed blog and instructions of the project is described in blog.

Run Command

Jacoco data file location - baseDir / module3 / target / aggregate.exec

Jacoco report location - baseDir / module3 / target / site / jacoco-aggregate / index.html

  • Unit testing + jacoco reporting. Note: Set a lower Coverage ratio in pom.xml

$ mvn clean install

  • Integration testing + jacoco reporting. Note: Set a lower Coverage ratio in pom.xml

$ mvn clean install -P integration-test

-Unit + Integration testing + jacoco merged reporting.

$ mvn clean install -P testAll

Note: You may add additional configuration for jacoco and control the behaviour. For additional configuration details visit here.

Result:

The below test coverage report shows coverage for testAll profile. The other important point to consider here is we have tried to increase the coverage of module1 method concatenation from module3 by running cucumber tests. Cucumber tests can easily be replaced by any other functional test frameworks like Karate API Testing Framework.

Coverage Report All

SonarQube

To use the merged JaCoCo report, SonarQube configuration has been added to the pom.xml file in module1 and module2:

  <properties>
    <sonar.coverage.jacoco.xmlReportPaths>../module3/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
  </properties>

To scan the code, run something like the following:

mvn sonar:sonar -Dsonar.projectKey=jacoco-multi-module-sample -Dsonar.host.url=https://sonarqube-test.tools.nykredit.it -Dsonar.token=<token>

Be aware that the scanner must be run using Java 17 whereas the project build uses Java 8.

About

This is an example of multi modular maven project with jacoco coverage for unit, integration and functional testing and generating a merged final report in jacoco.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 95.2%
  • Gherkin 4.8%