I would like to pick the only one module from which coverage is not “consumed”. The name of this module is “jfxsoft.easymvc.it”. This module contains complementary tests for rest of the modules.
The plugin configuration of JaCoCo is same for all modules and I already posted the configuration in my previous posts. For Sonar plugin, I have defined a bunch of properties, which I can also share and then just performing Maven Sonar plugin to do the magic.
JaCoCo plugin configuration
<!-- org.jacoco.jacoco-maven-plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${maven.jacoco.plugin.version}</version>
<executions>
<!-- Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed. -->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo
runtime agent. -->
<propertyName>jacoco.agent.argLine</propertyName>
<append>true</append>
</configuration>
</execution>
<!-- Ensures that the code coverage report for unit tests is created
after unit tests have been run. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo
runtime agent. -->
<propertyName>jacoco.agent.it.argLine</propertyName>
<append>true</append>
</configuration>
</execution>
<!-- Ensures that the code coverage report for integration tests is created
after unit tests have been run. -->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
<!-- Merge jacoco results -->
<execution>
<id>merge-unit-and-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}/coverage-reports/</directory>
<includes>
<include>jacoco-ut.exec</include>
<include>jacoco-it.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/coverage-reports/jacoco.all.exec</destFile>
</configuration>
</execution>
<!-- Aggregate results -->
<execution>
<id>create-merged-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/coverage-reports/jacoco.all.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Basically this will first configure, where to store results of UT and IT:
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
Than using merge goal it will take results from these two directories and create one merged result called jacoco.all.exec
.
Once the single “jacoco.all.exec” is created, aggregate result will be generated and stored in directory
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregate</outputDirectory>
At this state, every single module in the project contains it’s own jacoco-aggregate result.
The sonar properties are:
<sonar.organization>jfxsoft</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.junit.reportPaths>${project.build.directory}/surefire-reports,${project.build.directory}/failsafe-reports</sonar.junit.reportPaths>
<sonar.java.pmd.reportPaths>${project.build.directory}/pmd.xml</sonar.java.pmd.reportPaths>
<sonar.java.checkstyle.reportPaths>${project.build.directory}/checkstyle-result.xml</sonar.java.checkstyle.reportPaths>
<sonar.java.spotbugs.reportPaths>${project.build.directory}/spotbugsXml.xml</sonar.java.spotbugs.reportPaths>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.exclusions>**/generated-sources/**,**/generated-test-sources/**</sonar.exclusions>
The most important property is sonar.coverage.jacoco.xmlReportPaths
which correcponds with the path where the jacoco-aggregate result is located.
So far this configuration works as expected which means that when a module contains some tests (either unit or integration), results will be merged, aggregated and sent to sonar. That is a reason of having about 10% coverage. I’m happy with this, but I want more.
As I already tried to explain, I have a module called “jfxsoft.easymvc.it”, which contains complex tests. This means it runs a final application and check behaviour of an application as one big piece. Thanks to this I hope I will be able to cover more lines because sometimes it was not possible for me to make a test in the one “source” module.
Configuration of JaCoCo is same for this module as for the others so in the end I will also get jacoco-aggregate directory with result. BUT this time Sonar is not able to process the results and add them to the rest.