I want to write the unit test of the method just like
public void complete() {
System.exit(0);
}
I tried these instructions:
- How to test methods that call System.exit()?
- OR the very details is in : https://www.dontpanicblog.co.uk/2022/10/30/testing-system-exit/
With these ways, the unit test with System.exit is covered 100% when I run it individually. However, when I run it with mvn clean install & jacoco-maven-plugin, it says that the method is not covered in unit test
The problem can be pre-produced with the code on: https://github.com/hotblac/system-exit/tree/junit5 And the jacoco config on pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<excludes>
<exclude>*Test</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>90%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>