PulseExploreJournal ClubDebatesTrendingResearchersJournals
Instagram
HomeExploreJournal ClubTrending
Synapse
⌘+K
Synapse
March 8, 2026Applied Sciences2 citationsOpen Access

A Logic-Guided and Explainable Approach to LLM-Based Unit Test Generation

View Full Paper
CZCong ZengMLMeng LiLFLiu Fei

Key Points

  • This research aims to enhance unit test generation through a transparent, logic-guided method using Large Language Models.
  • Developed Logic-CoT, a white-box generation paradigm for test cases.
  • Constructed logical node state vectors and execution paths from control flow graphs.
  • Utilized a template-based method following the Arrange–Act–Assert pattern for test code initialization.
  • Logic-CoT outperforms existing methods in compilation success and runtime pass rates.
  • Demonstrated improvements in assertion pass rates and branch coverage through logical reasoning.
  • Ablation studies confirmed that each Logic-CoT component enhances test case effectiveness.

Abstract

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.

Ask AI
Helpful
Bookmark
Share
View Full Paper

Cite This Study

Zeng et al. (2026) studied this question.

synapsesocial.com/papers/69acc5bd32b0ef16a40508c1https://doi.org/10.3390/app16052542
Ask AI
Helpful
Bookmark
Share
View Full Paper