A quick guide on how to check for code coverage using IntelliJ, Jacoco, and SonarQube.
You can select a package or class to run tests with coverage. A run configuration is automatically created which you can then modify as necessary.
Run tests with coverage:
Run tests with coverageCoverage console
File explorer
Add the following dependency in pom.xml:
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
</dependency>
Wildcard syntax:
** matches zero or more directories* matches zero or more characters? matches a single character<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<includes>
<include>**/com/tech/payment/**/*</include>
</includes>
<excludes>
<exclude>**/com/tech/payment/config/**/*</exclude>
<exclude>**/com/tech/payment/constants/*Enum.class</exclude>
<exclude>**/com/tech/payment/kafka/**/*</exclude>
</excludes>
</configuration>
</plugin>
Here, we are:
com.tech.paymentcom.tech.payment.configEnum.class in any sub-package under the sub-package com.tech.payment.constantscom.tech.payment.kafkaRun mvn clean package
Jacoco site report
target/jacoco/site folderindex.html with a web browserSonarQube report