一句话:提出 JUnitGenie 框架,将代码知识与 LLM 语义能力结合,实现路径敏感的高覆盖单元测试生成。
单元测试对软件质量保障至关重要,但编写与维护成本高。已有的自动化测试生成方法(传统启发式方法与近期基于大语言模型的方法)本质上是路径不敏感的:它们依赖固定启发式规则或有限的上下文信息,无法推理深层控制流结构,因而在覆盖深层或复杂执行路径时表现不佳。本文提出路径敏感框架 JUnitGenie,通过将代码知识与大语言模型的语义能力相结合来指导上下文感知的单元测试生成。该框架先从 Java 项目中抽取代码知识,再将其蒸馏为结构化提示,引导模型生成高覆盖率测试。作者在来自十个真实 Java 项目的 2258 个复杂焦点方法上进行了评估,结果显示 JUnitGenie 能生成有效测试,相比启发式与基于 LLM 的基线,分支覆盖率与行覆盖率平均分别提升 29.60% 与 31.00%。此外,生成的测试用例还发现了真实缺陷,并已被开发者确认与修复。
Unit testing is essential for software quality assurance, yet writing and maintaining tests remains time-consuming and error-prone. To address this challenge, researchers have proposed various techniques for automating unit test generation, including traditional heuristic-based methods and more recent approaches that leverage large language models (LLMs). However, these existing approaches are inherently path-insensitive because they rely on fixed heuristics or limited contextual information and fail to reason about deep control-flow structures. As a result, they often struggle to achieve adequate coverage, particularly for deep or complex execution paths. In this work, we present a path-sensitive framework, JUnitGenie, to fill this gap by combining code knowledge with the semantic capabilities of LLMs in guiding context-aware unit test generation. After extracting code knowledge from Java projects, JUnitGenie distills this knowledge into structured prompts to guide the generation of high-coverage unit tests. We evaluate JUnitGenie on 2,258 complex focal methods from ten real-world Java projects. The results show that JUnitGenie generates valid tests and improves branch and line coverage by 29.60% and 31.00% on average over both heuristic and LLM-based baselines. We further demonstrate that the generated test cases can uncover real-world bugs, which were later confirmed and fixed by developers.
DOI 原文 ·
@inproceedings{paperbot9205,
title = {Navigating the Labyrinth: Path-Sensitive Unit Test Generation with Large Language Models},
author = {Dianshu Liao and Xin Yin and Shidong Pan and Chao Ni and Zhenchang Xing and Xiaoyu Sun},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00063}
}