A Logic-Guided and Explainable Approach to LLM-Based Unit Test Generation
Applied Sciences · 06.03.2026 · 16 (5) · 2542
DOI: 10.3390/app16052542 ↗Kurz gefasst
Fachartikel in der Zeitschrift Applied Sciences, online erschienen am 06.03.2026. Verfasst von Cong Zeng und 5 weiteren Autor:innen. Die Arbeit wurde bisher 2-mal zitiert (Crossref) und nennt 25 Literaturangaben. Der Volltext ist frei zugänglich (Open Access, CC BY 4.0). Gefördert von: National Natural Science Foundation of China, Hunan Provincial Natural Science Foundation, Hunan Provincial Teaching Reform Project.
Abstract (Originalsprache)
Large Language Models (LLMs) have demonstrated considerable potential in automated unit test generation; however, most existing approaches rely on a black-box paradigm that directly maps code under test to test code, often resulting in low compilation success rates, limited branch coverage, high assertion failure rates, and poor interpretability. Inspired by the human process of developing test cases, this paper proposes Logic-CoT, a white-box generation paradigm that follows a code under test–logical reasoning–test code workflow. The proposed approach consists of three stages: in the logical inference stage, logical node state vectors and execution paths are constructed from the control flow graph of the code under test, and input values and oracles satisfying state constraints are derived; in the test case construction stage, a template-based method is used to initialize test code conforming to the Arrange–Act–Assert pattern, with test intentions explicitly documented as comments; in the repair stage, syntactic errors and assertion failures are handled in a layered manner, where the former are corrected without altering test logic and the latter trigger logic reflection based on discrepancies between expected and actual outcomes, leading to state updates and test case reconstruction. This design forms a closed-loop process of reasoning, generation, and repair. Experiments on the QuixBugs, Apache Commons, HumanEval, and SV-COMP benchmarks show that Logic-CoT consistently outperforms state-of-the-art approaches such as ChatUniTest in terms of compilation success rate, runtime pass rate, assertion pass rate, branch coverage, average repair iterations for faulty code, and interpretability. Ablation studies further demonstrate that each component of Logic-CoT contributes effectively to improving the overall quality and effectiveness of generated test cases. These results indicate that Logic-CoT improves the reliability and interpretability of LLM-generated unit tests in practical software testing scenarios.
Förderung
- National Natural Science Foundation of China
- Hunan Provincial Natural Science Foundation
- Hunan Provincial Teaching Reform Project
- industry-funded research project
Zitieren
APA
Zeng, C., Li, M., Liu, F., Yang, X., Liu, J., & Yan, S. (2026). A Logic-Guided and Explainable Approach to LLM-Based Unit Test Generation. Applied Sciences, 16(5), 2542. https://doi.org/10.3390/app16052542
Vancouver
Zeng C, Li M, Liu F, Yang X, Liu J, Yan S. A Logic-Guided and Explainable Approach to LLM-Based Unit Test Generation. Applied Sciences. 2026;16(5):2542. doi:10.3390/app16052542
BibTeX
@article{Zeng2026,
author = {Zeng, Cong and Li, Meng and Liu, Fei and Yang, Xiaohua and Liu, Jie and Yan, Shiyu},
title = {A Logic-Guided and Explainable Approach to LLM-Based Unit Test Generation},
journal = {Applied Sciences},
year = {2026},
volume = {16},
number = {5},
pages = {2542},
doi = {10.3390/app16052542}
}
EUVIMED