arXiv:2509.24148cs.SEcs.AI2025-09中稿 · the 37th IEEE Inte…被引 2

用测试驱动生成整个代码库,让AI自动写代码并根据测试反馈迭代优化。

TENET: One Step Toward Test-Driven Development for Repository-Level Code Generation

  • 通过精选测试用例覆盖多样使用场景,提升代码生成效率。
  • 在RepoCod和RepoEval上分别达到69.08%和81.77%的Pass@1,优于基线。
  • 首次系统分析测试集特征对LLM生成性能的影响,适合研究TDD与AI协同者。

测试驱动开发(TDD)要求开发者在编码时同步编写并执行测试。随着大语言模型(LLMs)的发展,开发者可将代码编写转化为定义测试作为可执行规范,并由AI代理完成代码生成。然而,在开发者编写的测试下实现代码库级别的TDD仍具挑战,需解决三方面问题:(1)规范增强:从语义丰富的大型测试套件中识别出简洁且具有代表性的测试子集;(2)检索增强:利用测试指导推理与上下文检索;(3)测试驱动优化:基于测试反馈进行迭代改进。我们提出TENET,一种面向代码库级代码生成的代理框架。TENET包含:(1)测试夹具机制,通过最大化目标使用场景多样性来选择精简测试集;(2)定制化代理工具集,实现高效检索与调试;(3)基于反思的优化流程,持续分析失败并更新实现。TENET在不同主干模型上均显著优于最强基线,在Claude Sonnet 4下于RepoCod和RepoEval上分别取得69.08%和81.77%的Pass@1,提升9.49和2.17个百分点。此外,我们首次系统研究了测试集特性对LLM代理在TDD环境下性能的影响。

原文摘要 · Abstract (English)

Test-Driven Development (TDD) is a widely adopted practice that requires developers to create and execute tests alongside implementation. With recent advances in Large Language Models (LLMs), developers can shift from manually writing the code to defining tests as executable specifications and delegating code synthesis to AI agents. However, enabling repository-level TDD under developer-written tests is challenging, requiring: (1) specification enhancement: identifying a concise yet representative test subset from large suites with rich task semantics; (2) retrieval augmentation: using tests to guide reasoning and context retrieval; and (3) test-driven refinement: interpreting test feedback for iterative improvement. We propose TENET, an agentic framework for repository-level code generation under the TDD paradigm. TENET includes: (1) a test harness mechanism that selects a concise test suite to maximize diversity of the target usage scenarios; (2) a tailored agent toolset for efficient retrieval and debugging; and (3) a reflection-based refinement workflow that iteratively analyzes failures and updates implementations. TENET consistently outperforms the strongest baselines across backbones, achieving 69.08% and 81.77% Pass@1 on RepoCod and RepoEval with Claude Sonnet 4, improving by 9.49 and 2.17 percentage points, respectively. Additionally, we present the first systematic study of how test suite characteristics influence LLM agent performance in TDD settings.

测试驱动代码生成AI代理LLM

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。