arXivDaily arXiv每日学术速递 周一至周五更新
北美退伍军人节(Veterans Day),12 日无更新
arXiv 2602.03557cs.SE
收藏

从函数到类的测试驱动代码生成规模化:一项实证研究

Scaling Test-Driven Code Generation from Functions to Classes: An Empirical Study

Chengdu Institute of Computer Applications, Chinese Academy of Sciences(中国科学院成都计算机应用研究所);University of Chinese Academy of Sciences(中国科学院大学);Institute of Multidisciplinary Research for Advanced Materials (IMRAM), Tohoku University(东北大学先进材料跨学科研究所);Shenzhen Institutes of Advanced Technology, Chinese Academy of Sciences(中国科学院深圳先进技术研究院);Artificial Intelligence Research Institute, Shenzhen University of Advanced Technology(深圳高等研究院人工智能研究所)

Yunhao Liang, Ruixuan Ying, Shiwen Ni, Zhe Cui

AI总结:

本文提出一种测试驱动代码生成框架,通过迭代方法提升类级代码生成的正确性和可靠性。

摘要:

测试驱动开发(TDD)已被采用以通过使用可执行规范来提高基于大语言模型(LLM)的代码生成。然而,现有的TDD风格代码生成研究大多局限于函数级任务,留下类级合成领域未被充分探索,该领域涉及多个方法通过共享状态和调用依赖进行交互。在本文中,我们通过迭代TDD框架将测试驱动代码生成从函数扩展到类。我们的方法首先分析类内方法依赖性以推导可行的生成计划,然后在方法级公共测试下逐步实现每个方法,使用反射式执行反馈和有界的修复迭代。为了支持测试驱动生成和严谨的类级评估,我们构建了ClassEval-TDD,这是ClassEval的清理和标准化变体,具有一致的规范、确定性的测试环境和完整的类级公共测试。我们跨八个LLM进行实证研究,并与最强的直接生成基线(最佳的整体、增量和组合策略)进行比较。我们的类级TDD框架在类级正确性上始终提高了12到26个绝对点,并实现了高达71%完全正确的类,同时仅需要平均少量的修复。这些结果表明,测试驱动生成可以有效扩展到孤立函数之外,并显著提高类级代码生成的可靠性。所有代码和数据均在https://anonymous.4open.science/r/ClassEval-TDD-C4C9/上提供。

英文摘要:

Test-driven development (TDD) has been adopted to improve Large Language Model (LLM)-based code generation by using tests as executable specifications. However, existing TDD-style code generation studies are largely limited to function-level tasks, leaving class-level synthesis where multiple methods interact through shared state and call dependencies underexplored. In this paper, we scale test-driven code generation from functions to classes via an iterative TDD framework. Our approach first analyzes intra-class method dependencies to derive a feasible generation schedule, and then incrementally implements each method under method-level public tests with reflection-style execution feedback and bounded repair iterations. To support test-driven generation and rigorous class-level evaluation, we construct ClassEval-TDD, a cleaned and standardized variant of ClassEval with consistent specifications, deterministic test environments, and complete method-level public tests. We conduct an empirical study across eight LLMs and compare against the strongest direct-generation baseline (the best of holistic, incremental, and compositional strategies). Our class-level TDD framework consistently improves class-level correctness by 12 to 26 absolute points and achieves up to 71% fully correct classes, while requiring only a small number of repairs on average. These results demonstrate that test-driven generation can effectively scale beyond isolated functions and substantially improve class-level code generation reliability. All code and data are available at https://anonymous.4open.science/r/ClassEval-TDD-C4C9/

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑