Super-Jacoco: A One‑Stop Java Code Coverage Platform with Full and Diff Support
Super‑Jacoco is a one‑stop Java code‑coverage platform built on JaCoCo and Git that non‑intrusively gathers both full‑stack and incremental (diff) coverage for unit and manual tests, visualizes results, scales across distributed nodes, and provides REST APIs for triggering and retrieving coverage data.
Super-Jacoco is a one‑stop Java code coverage collection platform built on top of JaCoCo and Git. It can collect full‑stack and incremental (diff) coverage data with low cost and without any code intrusion.
Background
In software delivery, unit testing, interface testing, and functional testing are used to guarantee quality. However, test case design often suffers from problems such as duplicated test logic, uncovered exception scenarios, and uncertain coverage of automated test cases.
Developers write many unit tests that repeatedly execute the same code path, leaving some edge cases untested.
Testers review test cases repeatedly, yet some exceptional scenarios remain uncovered.
Automated interface test cases cannot guarantee that all code logic is exercised.
To ensure comprehensive testing with the minimal number of cases, the industry recommends analysing coverage of changed code and supplementing test cases accordingly. Existing tools like JaCoCo and EMMA only support full‑stack coverage and cannot meet the need for precise incremental coverage.
Super‑Jacoco Overview
Super‑Jacoco extends JaCoCo and Git to provide a platform that can collect both full and diff coverage in a non‑intrusive way. It supports on‑the‑fly collection (no code modification required) and can be integrated with environment deployment platforms (e.g., ebase) by adding -javaagent:jacocoagent.jar=includes=com.* to the JVM start command.
Key Features
General : Supports both unit‑test and manual‑test coverage, full‑stack and diff coverage.
Non‑intrusive : Uses on‑the‑fly mode, no changes to source code are needed.
High Availability : Distributed architecture with unlimited task‑machine scaling.
Visualization : Generates HTML coverage reports for easy analysis.
Architecture & Workflow
To collect incremental coverage, two steps are required:
Obtain the list of changed methods between two versions (e.g., master and feature branches) using JGit.
Modify JaCoCo to accept the method list as a parameter so that only those methods are instrumented.
The overall process is illustrated in the following diagram:
Example code for extracting incremental methods (partial snippet):
1) 拉取 master(参照分支)和 feature(提测分支)代码
2) 使用 JGit 对两个分支源码进行比对,获取增量代码列表JaCoCo’s Analyzer.analyzeClass method creates an ASM visitor via createAnalyzingVisitor . The probe calculation occurs in ClassProbesAdapter.visitMethod . By overriding visitMethod to process only the methods identified in the diff list, incremental coverage can be achieved. The core modification looks like this:
// Pseudo‑code illustrating the overridden method
@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
if (diffMethodSet.contains(name + descriptor)) {
return super.visitMethod(access, name, descriptor, signature, exceptions);
}
return null; // skip non‑diff methods
}API Endpoints
Unit‑test coverage collection:
URL: /cov/triggerUnitCover
Method: POST
Body: {"uuid":"uuid","type":1,"gitUrl":"git@git","subModule":"","baseVersion":"master","nowVersion":"feature","envType":"-Ptest"}
Response: {"code":200,"data":true,"msg":"msg"}Retrieve unit‑test coverage result:
URL: /cov/getUnitCoverResult
Method: GET
Param: uuid (String)
Response: {"code":200,"data":{"coverStatus":1,"errMsg":"msg","lineCoverage":100.0,"branchCoverage":100.0,"logFile":"file content","reportUrl":"http://"},"msg":"msg"}Environment coverage collection:
URL: /cov/triggerEnvCov
Method: POST
Body: {"uuid":"uuid","type":1,"gitUrl":"git@git","subModule":"","baseVersion":"master","nowVersion":"feature","address":"127.0.0.1","port":"8088"}
Response: {"code":200,"data":true,"msg":"msg"}Retrieve environment coverage result:
URL: /cov/getEnvCoverResult
Method: GET
Param: uuid (String)
Response: {"code":200,"data":{"coverStatus":1,"errMsg":"msg","lineCoverage":100.0,"branchCoverage":100.0,"logFile":"file content","reportUrl":"http://"},"msg":"msg"}Deployment Steps
Install MySQL and execute sql/db.sql to create tables.
Install JDK 1.8 and Maven 3.
Clone the repository, modify application.properties with your database and GitLab settings.
Run mvn package -Dmaven.test.skip=true to build super-jacoco.jar .
Start the service: nohup java -jar super-jacoco.jar & (default port 8899).
For more details, refer to the GitHub project: https://github.com/didi/super-jacoco
Didi Tech
Official Didi technology account
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.