In maven project, when configuring multi-threaded execution for unit tests, the coverage data reported by Cobertura is incorrect. Moreover, the results vary with each execution。
My configuration is as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<forkCount>1C</forkCount>
<reuseForks>true</reuseForks>
<parallel>classesAndMethods</parallel>
<threadCount>4</threadCount>
<trimStackTrace>true</trimStackTrace>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>xml</format>
</formats>
<outputDirectory>${project.reporting.outputDirectory}/cobertura</outputDirectory>
<encoding>UTF-8</encoding>
<aggregate>true</aggregate>
<check>
</check>
</configuration>
</plugin>
The issue occurs in my actual business project. However, it cannot be reproduced in a simpler example project.
As mentioned above. After I removed the configuration lines in the maven-surefire-plugin, the coverage data reported by Cobertura is correct, and, the results of multiple executions are the same.
Finally,I figured out this question myself.Hope it can help someone else. https://github.com/cobertura/cobertura/issues/434 I just remove those lines and deploy a new version into my own repository, and it works for me.