Backend Development 20 min read

Automated Unit Test Generation for Exception Recall in C/C++ Backend Systems

This article presents a comprehensive approach to automatically generate unit tests for C/C++ backend services, leveraging static code analysis, white‑box techniques, and fuzzing to create high‑coverage test cases that proactively detect stability issues without manual effort.

Baidu Intelligent Testing
Baidu Intelligent Testing
Baidu Intelligent Testing
Automated Unit Test Generation for Exception Recall in C/C++ Backend Systems

The paper introduces a white‑box method for recalling abnormal issues by automatically generating unit tests, describing the end‑to‑end construction from code understanding, high‑coverage test case creation, test code generation, to failure analysis.

It first outlines the limitations of existing anomaly detection methods such as stress testing, functional testing, and static scanning, highlighting their high cost or latency, and argues that unit testing combined with static analysis offers a more sustainable solution.

By dissecting the unit‑test creation process into four steps—identifying target functions, analyzing code, constructing test data, and generating test code—the authors propose a pipeline that extracts function features via static analysis (using cppcheck), stores them in XML, and feeds them into a test case generator.

The test data generation leverages fuzzing techniques, including both mutation‑based (e.g., AFL‑fuzz) and generation‑based methods, employing coverage metrics and constraint solving (e.g., Z3) to guide path selection and reduce test explosion.

Path selection involves constraint solving, reachability analysis, and path merging to focus on meaningful branches.

Candidate data sources combine static boundary values and dynamic logs.

Test case reduction uses pairwise (2‑wise) combinatorial testing and heuristic/meta‑heuristic algorithms to prune redundant cases.

Generated test cases are compiled (e.g., using GTest for death tests) and executed, with failure information captured via stack trace analysis, de‑duplication, and severity prediction.

The architecture integrates code analysis, test data generation, and test code generation into a scalable system that supports both batch (stock) and incremental (change‑driven) modes, deployed across hundreds of backend modules at Baidu, achieving over 50% function coverage and significant reduction in manual testing effort.

Results show the system has generated millions of lines of test code, recalled over 900 historical issues and 200 incremental issues, and demonstrated high coverage with low resource consumption.

software reliabilityC++unit testingStatic Analysisfuzzingtest generation
Baidu Intelligent Testing
Written by

Baidu Intelligent Testing

Welcome to follow.

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.