PulseExploreJournal ClubDebatesTrendingResearchersJournals
Instagram
HomeExploreJournal ClubTrending
Synapse
⌘+K
Synapse
February 9, 2026ACM Transactions on Software Engineering and Methodology8 citations

Automated Unit Test Generation via Chain of Thought Prompt and Reinforcement Learning from Coverage Feedback

View Full Paper
JZJunwei ZhangXHXiaozhi HuXXXin Xia

Key Points

  • The aim is to enhance automated unit test generation using large language models by addressing semantic understanding and test diversity.
  • Developed a CoT dataset with focal methods and corresponding unit tests.
  • Fine-tuned CodeLlama 7B as the policy model and CodeGPT as the reward model.
  • Utilized Proximal Policy Optimization (PPO) to optimize unit test generation.
  • Evaluated approach using the Defects4J benchmark for performance metrics.
  • TestCTRL significantly outperforms state-of-the-art models in line and branch coverage.
  • Enhanced bug detection performance observed with TestCTRL.
  • Improvements noted in the naturalness and validity of generated tests.

Abstract

Recently, large language models (LLMs) have shown promising results in code generation, and several automated test generation approaches based on LLMs have been proposed. Although these approaches achieve promising performance, they suffer from two limitations. First, they lack the intrinsic understanding of the semantic intricacies and logical constructs inherent to the focal method. Second, they ignore the diversity of the generated tests and generate tests with limited code coverage. To alleviate these two limitations, in this work, we propose a novel approach named TestCTRL that optimizes LLMs for unit test generation by the chain-of-thought (CoT) prompt and reinforcement learning (RL) strategy. Specifically, we first build a new CoT dataset, containing the focal methods, corresponding unit tests, and CoT prompts. The CoT prompt includes the intention and possible test input values. Then, the CoT dataset is used to fine-tune one LLM (i.e., CodeLlama 7B) that can be seen as the policy model in RL. Meanwhile, we fine-tune another LLM (i.e., CodeGPT) as the reward model by predicting the line coverage of the focal method and its test. Moreover, we employ the Proximal Policy Optimization (PPO) algorithm to optimize the policy model and generate unit tests. We use the Defects4J benchmark to evaluate our approach from three perspectives (i.e., naturalness, validity, and code coverage). To avoid data leakage threats, we filtered out data from the CoT dataset that have the same focal method and test case names as those in the Defects4J. The experimental results demonstrate that TestCTRL outperforms state-of-the-art baselines in line and branch coverages, respectively. Besides, TestCTRL improves bug detection performance. We also investigate the reason for the proposed approach's superiority.

Ask AI
Helpful
Bookmark
Share
View Full Paper

Cite This Study

Zhang et al. (2025) studied this question.

synapsesocial.com/papers/698978dff0ec2af6756e70e0https://doi.org/10.1145/3745765
Ask AI
Helpful
Bookmark
Share
View Full Paper

Also Consider

Synapse has enriched 5 closely related papers on similar clinical questions. Consider them for comparative context:

  1. 1No More Manual Tests? Evaluating and Improving ChatGPT for Unit Test Generation2023 · 53 citations
  2. 2Benefits and limitations of automated software testing: Systematic literature review and practitioner survey2012 · 150 citations
  3. 3The Daikon system for dynamic detection of likely invariants2007 · 1,068 citations
  4. 4GP-BART: A novel Bayesian additive regression trees approach using Gaussian processes2023 · 10 citations
  5. 5Less is More: On the Importance of Data Quality for Unit Test Generation2025 · 1 citations