Backend Development 14 min read

Implementation and Architecture of the Jingwei Java Code Coverage Statistics Tool Using JaCoCo

This article details the design, deployment steps, technical architecture, and operational workflow of the Jingwei system—a Java code‑coverage solution built on JaCoCo that automates coverage collection, merges execution data, and visualizes results to improve testing quality and efficiency.

Dada Group Technology
Dada Group Technology
Dada Group Technology
Implementation and Architecture of the Jingwei Java Code Coverage Statistics Tool Using JaCoCo

Background : As test developers aim to improve both test quality and efficiency, code coverage becomes a crucial metric. To address current testing gaps, the Jingwei team built an in‑house code‑coverage tool that automatically identifies untested code and expands test scenarios.

Tool Introduction : JaCoCo, an open‑source Java code‑coverage library, can be embedded via Ant, Maven, or the Eclipse EclEmma plugin and supports JavaAgent instrumentation. Jingwei adopts the on‑the‑fly mode, requiring only the -javaagent JVM argument to inject probes without modifying source code.

Implementation Principle : The coverage workflow consists of seven steps: (1) Deploy jacocoagent.jar on target machines, (2) Configure environment and test cases, (3) Execute test cases, (4) Retrieve the binary .exec file, (5) Obtain source and diff files, (6) Fetch compiled class packages, and (7) Perform coverage aggregation and visualization.

Technical Architecture : The system follows a four‑stage pipeline—coverage task trigger, resource initialization, resource processing, and front‑end rendering. Workers poll a task queue, filter duplicates, and execute tasks concurrently. Initialization gathers .exec , class, and source files via APIs from the deployment platform and Git repository.

Detailed Implementation : Coverage Trigger: Tasks are created in the Jingwei platform; selecting "full" mode runs all regression cases, after which coverage is calculated per application. Build Mechanism: Full‑task execution runs every regression test, while custom tasks allow selective runs. Resource Initialization: Three parallel threads download the .exec binary, compiled class zip, and branch source files. Resource Processing: Diff analysis (using JGit) merges branch and production code, annotates changed lines, and prepares data for coverage merging. Exec Merging: Distributed services generate multiple .exec files; they are merged with org.jacoco.core.tools.ExecFileLoader . Coverage Report Generation: XML reports contain metrics such as missed/covered instructions, branches, and lines, with visual cues (red, yellow, green) indicating coverage status.

UI Presentation : The front‑end displays overall coverage, incremental (diff) coverage, and detailed line‑by‑line results, highlighting instruction, branch, complexity, and line coverage using color coding.

System Features : Supports unit, manual, full, and diff coverage; non‑intrusive on‑the‑fly instrumentation; high availability via a distributed architecture; and rich visualizations for both incremental and full coverage.

Future Plans : Improve exception‑path coverage by instrumenting compiled bytecode, and optimize storage of line‑color data to reduce resource consumption.

Conclusion : In fast‑moving development environments, automated coverage collection like Jingwei’s significantly enhances test quality, though high coverage alone does not guarantee test thoroughness; low coverage reliably indicates quality issues.

BackendJavaCode Coveragesoftware qualityTesting AutomationJaCoCo
Dada Group Technology
Written by

Dada Group Technology

Sharing insights and experiences from Dada Group's R&D department on product refinement and technology advancement, connecting with fellow geeks to exchange ideas and grow together.

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.