一句话:提出基于仓库级代码知识图谱的多智能体 LLM 工具,自动生成高质量 Java 单元测试并发现真实缺陷。
针对现有基于 LLM 的单元测试生成工具仓库级上下文有限、生成流程僵化的问题,本文提出 TestAgent——一个以 VS Code 扩展形式实现的多智能体工具,用于为 Java 项目自动生成高质量单元测试。该方法构建仓库级代码知识图谱以提供上下文,并模仿人类开发者的结构化实践,协调三个专门智能体:Planner 推导测试需求,Generator 借助工具辅助检索合成可执行测试代码,Reviewer 依据执行反馈迭代精化测试。在六个 Java 项目的 1,451 个方法上进行评估,TestAgent 达到 92.34% 的行覆盖率,显著优于 EvoSuite、ChatUniTest 等基线;同时以 92.22% 的高精确率成功检测出 154 个真实缺陷,表明其在回归测试与缺陷发现中的实用价值。
Automated unit test generation plays a critical role in maintaining software quality, yet existing LLM-based tools often struggle with limited repository-level context and rigid generation workflows. In this paper, we present TestAgent, a multi-agent tool implemented as a VS Code extension that automates the generation of high-quality unit tests for Java projects using repository-level Code Knowledge Graphs. Unlike existing tools that rely on coarse-grained workflows, TestAgent mirrors the structured practices of human developers, who typically analyze requirements before writing tests and review results afterward, by coordinating three specialized agents: a Planner to derive testing requirements, a Generator to synthesize executable code via tool-assisted retrieval, and a Reviewer to iteratively refine tests based on execution feedback. Evaluation on 1,451 methods across six Java projects demonstrates that TestAgent achieves a 92.34% line coverage, significantly outperforming baselines like EvoSuite and ChatUniTest. Furthermore, the tool successfully detects 154 real-world bugs with high precision (92.22%), demonstrating its practical utility for regression testing and bug discovery. The tool source code and demonstration are available at: https://github.com/iSEngLab/TestAgent-VSCode-Extension.
@inproceedings{ShangZZHFC26,
title = {TestAgent: A Multi-Agent LLM Framework for Repository-Level Unit Test Generation},
author = {Ye Shang and Quanjun Zhang and Zhengyu Zhan and Ke Huang and Chunrong Fang and Zhenyu Chen},
booktitle = {FSE},
year = {2026},
doi = {10.1145/3803437.3806428}
}