一句话:提出 IntUT,用显式测试意图引导 LLM 生成高覆盖且具备 mock 能力的单元测试。
现有基于大语言模型(LLM)直接生成单元测试的方法往往覆盖率低、mock 能力不足,难以在实际开发中落地。本文提出 IntUT,通过显式的测试意图(如测试输入、mock 行为与预期结果)来有效引导 LLM,使其生成高质量测试用例。作者在三个工业 Java 项目及 live study 上进行了评估,结果表明以测试意图提示 LLM 能显著提升测试质量:分支覆盖率提升 94%,行覆盖率提升 49%。最后,作者收集了开发者使用 IntUT 为三个新 Java 项目生成测试用例的反馈,行覆盖率超过 80%,编写单元测试的效率提升 30% 以上。
The emergence of Large Language Models (LLMs) has accelerated the progress of intelligent software engineering technologies, which brings promising possibilities for unit test generation. However, existing approaches for unit tests directly generated from Large Language Models (LLMs) often prove impractical due to their low coverage and insufficient mocking capabilities. This paper proposes IntUT, a novel approach that utilizes explicit test intentions (e.g., test inputs, mock behaviors, and expected results) to effectively guide the LLM to generate high-quality test cases. Our experimental results on three industry Java projects and live study demonstrate that prompting LLM with test intention can generate high-quality test cases for developers. Specifically, it achieves the improvements on branch coverage by 94 % and line coverage by 49 %. Finally, we obtain developers' feedback on using IntUT to generate cases for three new Java projects, achieving over 80 % line coverage and 30 % efficiency improvement on writing unit test cases.
DOI 原文 ·
@inproceedings{paperbot8800,
title = {Test Intention Guided LLM-Based Unit Test Generation},
author = {Zifan Nan and Zhaoqiang Guo and Kui Liu and Xin Xia},
booktitle = {ICSE},
year = {2025},
doi = {10.1109/icse55347.2025.00243}
}