Backend Development 17 min read

Building a Backend Java Code‑Analysis Platform for Precise Testing and Application Slimming

This article describes how to construct a code‑analysis platform for Java micro‑services that builds a knowledge base through static, semi‑dynamic and dynamic analysis, enabling precise test‑case selection and safe removal of dead code to improve iteration efficiency and system maintainability.

Ctrip Technology
Ctrip Technology
Ctrip Technology
Building a Backend Java Code‑Analysis Platform for Precise Testing and Application Slimming

In large‑scale micro‑service environments, frequent requirement iterations lead to a rapid increase in applications, source code lines, and automated test cases, causing developers to spend excessive time navigating historical code and testers to execute many irrelevant regression cases, which severely hampers development efficiency.

To address this, the Ctrip travel technology team designed a code‑analysis platform that aggregates source code and test‑case information, identifies dead code (about one‑third of production code) and unrelated regression cases (about 68%), and provides tools for precise testing and application slimming.

The platform’s core analysis consists of three layers:

Static analysis: parses Java source files to extract method declarations and call relationships, recommended tool: java-callgraph2 .

Semi‑dynamic analysis: combines bytecode instrumentation with test‑case replay (using Ctrip’s open‑source AREX) to capture method chains exercised by test cases.

Dynamic analysis: leverages JVM method counters to collect production‑time execution frequencies without code intrusion, acknowledging the trade‑off of STW pauses.

The platformization process follows three key steps:

Knowledge‑base construction: collect application entry points, source code (via images), perform static analysis, and store method relationships in a graph database (e.g., Nebula‑Graph) alongside relational data.

Enriching test‑case information: replay automated test cases, capture invoked methods, and link them to the knowledge base, using AREX for non‑intrusive instrumentation.

Adding traffic data: periodically collect production method execution counts, merge them into the graph to reflect real‑time method usage.

Two primary application scenarios are demonstrated:

Precise testing: by comparing code diffs (using Git and a diff component) with the knowledge base, the platform recommends only the test cases that touch changed methods, achieving up to 99.2% of the coverage of full regression while reducing unrelated test execution by 68%.

Application slimming: the platform visualizes method reachability and production traffic, allowing developers to safely delete dead code; a pilot on 10% of services removed millions of lines of code with zero incidents and reduced image build time from tens of minutes to a few minutes.

In summary, the code‑analysis platform integrates static, semi‑dynamic, and dynamic techniques to build a comprehensive knowledge base, enabling closed‑loop workflows for precise testing and safe code slimming, thereby improving iteration speed and long‑term maintainability of backend Java services.

MicroservicesBackend Developmentcode analysistest automationstatic analysisDynamic Analysisapplication slimming
Ctrip Technology
Written by

Ctrip Technology

Official Ctrip Technology account, sharing and discussing growth.

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.