Fundamentals 5 min read

Integrating Incremental Unit Test Coverage into Test Environment Coverage with Maven Surefire and JaCoCo

This article describes a solution that merges incremental unit test coverage into overall test environment coverage by leveraging Maven Surefire Report Plugin and JaCoCo, detailing steps from CI platform integration, plugin configuration, report generation, to coverage platform processing, enabling comprehensive coverage analysis for release admission.

转转QA
转转QA
转转QA
Integrating Incremental Unit Test Coverage into Test Environment Coverage with Maven Surefire and JaCoCo

Background The incremental code scan data from ZLJ is used as a key criterion for release admission. While test environments already provide coverage statistics, many services rely on unit tests, and missing unit‑test coverage hampers accurate assessment. The proposed solution merges unit‑test incremental coverage into the overall test‑environment coverage.

Overall Solution

Test Platform

1. The CI platform sends the project name, branch name, and Git repository URL to the unit‑test platform, which then checks out the source code.

2. Modify the project's pom.xml to include the maven-surefire-report-plugin .

Converts generated XML reports to HTML.

Allows selection of which test classes to execute.

Supports JUnit 3, JUnit 4, and TestNG.

By default, the plugin does not run in every build lifecycle unless HTML output is needed.

Result: Opening surefire-report.htm shows the number of executed cases, pass rate, failed methods, and failure reasons.

JaCoCo Integration

3. Generate unit‑test coverage with JaCoCo by adding the parameter org.jacoco:jacoco-maven-plugin:prepare-agent to the Maven command.

4. It is recommended to add -Dmaven.test.failure.ignore=true so that test failures do not abort the build and prevent the creation of the .exec file.

After execution, a jacoco.exec file is produced in the target directory and is sent to the coverage statistics system.

Coverage Platform

1. Add a coverage‑statistics task. When the test platform receives a unit‑test execution request, it calls the coverage platform's API, providing source code address, JAR FTP address, and branch information. The platform then downloads the source, JAR, performs a code‑diff, and stores the diff results in a database.

2. Compute coverage. The article references a previous “on‑the‑fly” differential coverage approach where execution traces are collected in real time from the test server.

The new workflow allows the test platform to handle most tasks, enabling incremental unit‑test coverage statistics without modifying existing code.

At this point the entire process is complete. Readers are invited to share suggestions or alternative solutions.

Code CoverageCI/CDsoftware testingmavenunit testingJaCoCo
转转QA
Written by

转转QA

In the era of knowledge sharing, discover 转转QA from a new perspective.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.