Clarifying Semantics of In-Context Examples for Unit Test Generation
Chen Yang, Lin Yang, Ziqi Wang, Dong Wang, Jianyi Zhou, Junjie Chen
Abstract
Recent advances in large language models (LLMs) have enabled promising performance in unit test generation through in-context learning (ICL). However, the quality of in-context examples significantly influences the effectiveness of generated tests—poorly structured or semantically unclear test examples often lead to suboptimal outputs. In this paper, we propose CLAST, a novel technique that systematically refines unit tests to improve their semantic clarity, thereby enhancing their utility as in-context examples. The approach decomposes complex tests into logically clearer ones and improves semantic clarity through a combination of program analysis and LLM-based rewriting. We evaluated CLAST on four open-source and three industrial projects. The results demonstrate that CLAST largely outperforms UTgen, the state-of-the-art refinement technique, in both preserving test effectiveness and enhancing semantic clarity. Specifically, CLAST fully retains the original effectiveness of unit tests, while UTgen reduces compilation success rate (CSR), pass rate (PR), test coverage (Cov), and mutation score (MS) by an average of 12.90%, 35.82%, 4.65%, and 5.07%, respectively. Over 85.33% of participants in our user study preferred the semantic clarity of CLAST-refined tests. Notably, incorporating CLAST-refined tests as examples effectively improves ICL-based unit test generation approaches such as RAGGen and TELPA, resulting in an average increase of 25.97% in CSR, 28.22% in PR, and 45.99% in Cov for generated tests, compared to incorporating UTgen-refined tests. The insights from the follow-up user study not only reinforce CLAST’s potential impact in software testing practice but also illuminate avenues for future research.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
6 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models cites Efficient Memory Management for Large Language Model Serving with PagedAttention
- Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models cites HITS: High-coverage LLM-based Unit Test Generation via Method Slicing
- Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models cites Code-Aware Prompting: A Study of Coverage-Guided Test Generation in Regression Setting using LLM
- Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models cites On the Evaluation of Large Language Models in Unit Test Generation
- What Makes In-Context Examples Effective for Code Generation? cites Efficient Memory Management for Large Language Model Serving with PagedAttention
- Characterizing and Mitigating False-Positive Bug Reports in the Linux Kernel cites Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models
- Characterizing and Mitigating False-Positive Bug Reports in the Linux Kernel cites On the Evaluation of Large Language Models in Unit Test Generation
- Context Matters: Improving the Practical Reliability of LLM-Based Unit Test Generation (Experience Paper) cites Reflective Unit Test Generation for Precise Type Error Detection with Large Language Models
- Context Matters: Improving the Practical Reliability of LLM-Based Unit Test Generation (Experience Paper) cites HITS: High-coverage LLM-based Unit Test Generation via Method Slicing
- Context Matters: Improving the Practical Reliability of LLM-Based Unit Test Generation (Experience Paper) cites On the Evaluation of Large Language Models in Unit Test Generation
- HITS: High-coverage LLM-based Unit Test Generation via Method Slicing cites Code-Aware Prompting: A Study of Coverage-Guided Test Generation in Regression Setting using LLM
- On the Evaluation of Large Language Models in Unit Test Generation cites Efficient Memory Management for Large Language Model Serving with PagedAttention
Cited by top-tier papers6
- Reflective Unit Test Generation for Precise Type Error Detection with Large Language ModelsChen Yang, Ziqi Wang, Yanjie Jiang, Lin Yang et al.ASE 2025 · 1 citation
- CausalRepair: Bridging the Causality Gap in Large Language Model-Based Automated Program Repair via Dual-SlicingLinhao Wu, Yizhou Chen, Zhen Yang, Pengyu Xue et al.ISSTA 2026
- What Makes In-Context Examples Effective for Code Generation?Dongze Li, Songqiang Chen, Jialun Cao, Shing-Chi CheungISSTA 2026
- Characterizing and Mitigating False-Positive Bug Reports in the Linux KernelJiashuo Tian, Dong Wang, Chen Yang, Haichi Wang et al.FSE 2026
- Context Matters: Improving the Practical Reliability of LLM-Based Unit Test Generation (Experience Paper)Junjie Chen, Ziqi Wang, Lin Yang, Chen Yang et al.ISSTA 2026
Builds on10
- Efficient Memory Management for Large Language Model Serving with PagedAttentionWoosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng et al.SOSP 2023 · 1,016 citations
- Code-Aware Prompting: A Study of Coverage-Guided Test Generation in Regression Setting using LLMGabriel Ryan, Siddhartha Jain, Mingyue Shang, Shiqi Wang et al.FSE 2024 · 68 citations
- On the Evaluation of Large Language Models in Unit Test GenerationLin Yang, Chen Yang, Shutao Gao, Weijing Wang et al.ASE 2024 · 42 citations
- DeepTC-Enhancer: Improving the Readability of Automatically Generated TestsDevjeet Roy, Ziyi Zhang, Maggie Ma, Venera Arnaoudova et al.ASE 2020 · 32 citations
- HITS: High-coverage LLM-based Unit Test Generation via Method SlicingZejun Wang, Kaibo Liu, Ge Li, Zhi JinASE 2024 · 29 citations
Related papers
- Evaluating and Improving ChatGPT for Unit Test GenerationZhiqiang Yuan, Mingwei Liu, Shiji Ding, Kaixin Wang et al.FSE 2024 · 89 citations
- Beyond Coverage: Automatic Test Suite Augmentation for Enhanced Effectiveness using Large Language ModelsZeyu Lu, Peng Zhang, Yuge Nie, Yibiao Yang et al.OOPSLA 2026 · 1 citation
- PALM: Synergizing Program Analysis and LLMs to Enhance Rust Unit Test CoverageBei Chu, Yang Feng, Kui Liu, Hange Shi et al.ASE 2025 · 3 citations
- Test Intention Guided LLM-Based Unit Test GenerationZifan Nan, Zhaoqiang Guo, Kui Liu, Xin XiaICSE 2025 · 5 citations
- Rug: Turbo Llm for Rust Unit Test GenerationXiang Cheng, Fan Sang, Yizhuo Zhai, Xiaokuan Zhang et al.ICSE 2025 · 6 citations
