Lune

ISSTA2026Top-tier venue

Context Matters: Improving the Practical Reliability of LLM-Based Unit Test Generation (Experience Paper)

Junjie Chen, Ziqi Wang, Lin Yang, Chen Yang, Xiao Chu, Jianyi Zhou, Guangtai Liang, Qianxiang Wang, Dong Wang

Abstract

Automated unit test generation has recently benefited from advances in large language models (LLMs), yet our industrial deployments reveal a persistent gap between promising research results and practical usability. In real-world projects with complex frameworks and cross-file dependencies, LLM-generated tests frequently fail to compile, require costly manual repair, or provide unstable coverage improvements. This paper reports our experience in designing, deploying, and evaluating CATGen , a context-aware workflow for LLM-based unit test generation, informed by repeated industrial failures and refinements. Rather than relying on LLMs to infer incomplete project context, we found that compilation robustness critically depends on making project-level dependencies explicit, stabilizing test class scaffolding, and replacing iterative LLM-based repair with lightweight static analysis. These experience-driven insights shaped CATGen’s multi-stage design, which combines structured context retrieval, deterministic test skeleton construction, and program analysis–based post-processing. We evaluate CATGen on real-world complex focal methods from proprietary industrial projects and additionally on the Defects4J benchmark to assess generalizability. Across both settings, CATGen substantially improves compilation success and structural coverage while significantly reducing generation time and token consumption compared to existing LLM-based approaches. Our results demonstrate that reliable LLM-based unit test generation in practice depends less on prompt engineering alone and more on systematic engineering support grounded in real-world development constraints.

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.

Questions to start from

Lune can draw on

the full paper · related work

Get the answer

Free to start. No credit card required.

Lineage

  • CodaMosa: Escaping Coverage Plateaus in Test Generation with Pre-trained Large Language Models cites TOGA: A Neural Method for Test Oracle Generation
  • CodaMosa: Escaping Coverage Plateaus in Test Generation with Pre-trained Large Language Models cites On learning meaningful assert statements for unit test cases
  • TOGA: A Neural Method for Test Oracle Generation cites On learning meaningful assert statements for unit test cases
  • Evaluating and Improving ChatGPT for Unit Test Generation cites CodaMosa: Escaping Coverage Plateaus in Test Generation with Pre-trained Large Language Models
  • Evaluating and Improving ChatGPT for Unit Test Generation cites TOGA: A Neural Method for Test Oracle Generation
  • Evaluating and Improving ChatGPT for Unit Test Generation cites On learning meaningful assert statements for unit test cases
  • Evaluating and Improving ChatGPT for Unit Test Generation cites Learning Deep Semantics for Test Completion
  • Learning Deep Semantics for Test Completion cites CodaMosa: Escaping Coverage Plateaus in Test Generation with Pre-trained Large Language Models
  • Learning Deep Semantics for Test Completion cites TOGA: A Neural Method for Test Oracle Generation
  • Learning Deep Semantics for Test Completion cites On learning meaningful assert statements for unit test cases
Builds onCited byLeft to right by year; the more cited, the higher.

Builds on14

  1. CodaMosa: Escaping Coverage Plateaus in Test Generation with Pre-trained Large Language ModelsCaroline Lemieux, Jeevana Priya Inala, Shuvendu K. Lahiri, Siddhartha SenICSE 2023 · 221 citations
  2. On learning meaningful assert statements for unit test casesCody Watson, Michele Tufano, Kevin Moran, Gabriele Bavota et al.ICSE 2020 · 96 citations
  3. TOGA: A Neural Method for Test Oracle GenerationElizabeth Dinella, Gabriel Ryan, Todd Mytkowicz, Shuvendu K. LahiriICSE 2022 · 92 citations
  4. Evaluating and Improving ChatGPT for Unit Test GenerationZhiqiang Yuan, Mingwei Liu, Shiji Ding, Kaixin Wang et al.FSE 2024 · 89 citations
  5. Learning Deep Semantics for Test CompletionPengyu Nie, Rahul Banerjee, Junyi Jessy Li, Raymond J. Mooney et al.ICSE 2023 · 45 citations

Related papers

  1. Navigating the Labyrinth: Path-Sensitive Unit Test Generation with Large Language ModelsDianshu Liao, Xin Yin, Shidong Pan, Chao Ni et al.ASE 2025 · 2 citations
  2. Knowledge Matters: Injecting Project and Testing Knowledge into LLM-based Unit Test GenerationAnji Li, Mingwei Liu, Zhenxi Chen, Zheng Pei et al.ICSE 2026 · 2 citations
  3. LLM Test Generation via Iterative Hybrid Program AnalysisSijia Gu, Noor Nashid, Ali MesbahICSE 2026 · 6 citations
  4. STRUT: Structured Seed Case Guided Unit Test Generation for C Programs using LLMsJinwei Liu, Chao Li, Rui Chen, Shaofeng Li et al.ISSTA 2025 · 6 citations
  5. HITS: High-coverage LLM-based Unit Test Generation via Method SlicingZejun Wang, Kaibo Liu, Ge Li, Zhi JinASE 2024 · 29 citations
Dusk over the sea between two cliffs drawn in fine vertical lines