Backend Development 19 min read

Automated Unit Test Generation for Exception Recall in C/C++ Services

This article presents a white‑box, unit‑test‑driven approach for automatically generating C/C++ test cases that detect and recall runtime stability issues, detailing problem analysis, solution design, code‑analysis, test‑data generation, code generation, failure analysis, and deployment results across large‑scale backend modules.

DevOps
DevOps
DevOps
Automated Unit Test Generation for Exception Recall in C/C++ Services

Online stability problems are a major concern for product revenue and user experience, and traditional testing methods face technical bottlenecks. To address this, the authors propose a generic, fully automated unit‑test generation system that leverages white‑box techniques to recall abnormal issues in C/C++ services.

The paper first analyzes existing abnormal testing methods (stress, functional, unit, static scanning) and highlights their high cost or low recall. It then argues that unit‑test‑based recall offers significant advantages such as low resource consumption, easy data construction, and early bug detection.

A sustainable, high‑ROI stability‑issue recall funnel is introduced, combining passive static analysis with active intelligent unit tests (Intelligent UT). The solution consists of four key steps: confirming target functions, analyzing code, constructing test data, and generating test code.

Code analysis is performed using cppcheck, extracting function signatures, variable declarations, modifiers, and file‑level information into an XML‑based CodeStructData (CSD). Test‑data generation employs both generation‑based and mutation‑based fuzzing, guided by path selection, constraint solving (e.g., Z3), and coverage metrics to avoid test‑case explosion.

Test‑case combinatorial explosion is mitigated using pairwise (2‑wise) testing and heuristic/meta‑heuristic algorithms (AETG, IPO, genetic algorithms) to produce a minimal yet effective test suite, reducing over 90% of redundant cases.

Generated test code follows template‑based syntax rules (e.g., GTest death tests) to ensure compilable, runnable unit tests. Failure analysis captures stack traces, de‑duplicates crashes, and predicts failure causes, improving debugging efficiency.

The system supports both full‑scale (stock) and incremental (change‑based) deployment modes, integrating with internal data and visualization platforms to provide end‑to‑end testing, execution, analysis, and issue localization.

In production, the approach has generated tens of millions of lines of test code, achieving >50% function coverage and >20% branch coverage with negligible resource overhead and minimal human effort, successfully recalling hundreds of existing and new issues across 140+ backend modules.

software reliabilityC++unit testingStatic Analysisfuzzingtest generation
DevOps
Written by

DevOps

Share premium content and events on trends, applications, and practices in development efficiency, AI and related technologies. The IDCF International DevOps Coach Federation trains end‑to‑end development‑efficiency talent, linking high‑performance organizations and individuals to achieve excellence.

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.