基于契约的AI代理测试生成:规范驱动方法的实证评估
原标题:Grounding AI Agents in Contracts: An Empirical Evaluation of Spec-Driven Test Generation
AI 摘要
该研究提出了一种名为Spec-Driven Test Generation的测试生成方法,通过让AI代理在生成测试前先提取并记录代码的前置条件、后置条件和未定义行为,形成半形式化规范作为引导。在Google的90个历史生产bug上的评估显示,该方法相比传统基线在bug检测率上提升了9.8个百分点,分支覆盖率提升了2.5个百分点。LLM-as-a-Judge评估表明,该方法生成的测试套件在77.8%的情况下优于基线,在56.7%的情况下优于人类编写的测试。
正文节选
Grounding AI Agents in Contracts: An Empirical Evaluation of Spec-Driven Test Generation Abstract. LLM-based agents are increasingly used for coding tasks, where they have outperformed many classical approaches and scaled to repository-level tasks, such as test generation. However, when directly prompted to generate tests, these agents can fail to reason about the code and its underlying contracts, thereby missing edge cases and behavioral boundaries that affect test quality. To address this lim