paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Test-Driven Development and LLM-based Code Generation

测试驱动开发与基于大语言模型的代码生成
ASE Proceedings of the 39th IEEE/ACM International Conference on Automated Software Engineering2024匹配度 2/10 · 论文关注在提示中加入测试用例以提升LLM函数级代码生成成功率,属于LLM代码生成的提示增强/TDD实证,不涉及静态分析、形式化验证、浮点程序分析或贝叶斯程序分析,且研究目标本身是提升LLM/Agent能力,与用户画像核心方向不符。引用 24 inbox
Noble Saji Mathews, Meiyappan Nagappan
crossref: 2026-09-12

AI 速览

一句话:实证表明在提示中加入测试用例能显著提升LLM函数级代码生成的成功率,验证TDD范式在AI辅助编程中的价值。

该文探讨能否以及如何将测试驱动开发(TDD)融入AI辅助的代码生成流程。传统TDD要求先写测试再写实现,从而保证代码与需求一致;作者假设在给LLM提供问题描述之外再提供测试用例,可以提升生成代码的正确性。实验在MBPP与HumanEval两个函数级代码生成基准上进行,对比仅给问题描述与同时给出测试用例两种提示方式,并使用GPT-4与Llama 3等模型。结果一致表明,包含测试用例的提示在解决编程任务上取得更高的成功率,说明测试可作为有效的规约与验证信号。作者据此主张TDD是帮助确保LLM生成代码真正满足需求的一种有前景的范式。

问题
LLM直接依据问题描述生成的代码难以保证符合需求,如何将TDD的"先写测试"思想引入AI辅助代码生成以提升正确性尚不明确。
方法
在提示中除问题描述外额外提供测试用例,与仅给问题描述的基线对比,考察测试作为额外规约信息对LLM生成代码的影响。
评估
在MBPP与HumanEval函数级代码生成基准上,使用GPT-4与Llama 3等模型进行对比实验,统计不同提示方式下的任务求解成功率。
原文摘要(Abstract)

Recent Large Language Models (LLMs) have demonstrated significant capabilities in generating code snippets directly from problem statements. This increasingly automated process mirrors traditional human-led software development, where code is often written in response to a requirement. Historically, Test-Driven Development (TDD) has proven its merit, requiring developers to write tests before the functional code, ensuring alignment with the initial problem statements. Applying TDD principles to LLM-based code generation offers one distinct benefit: it enables developers to verify the correctness of generated code against predefined tests. This paper investigates if and how TDD can be incorporated into AI-assisted code-generation processes. We experimentally evaluate our hypothesis that providing LLMs like GPT-4 and Llama 3 with tests in addition to the problem statements enhances code generation outcomes. We experimented with established function-level code generation benchmarks such as MBPP and HumanEval. Our results consistently demonstrate that including test cases leads to higher success in solving programming challenges. We assert that TDD is a promising paradigm for helping ensure that the code generated by LLMs effectively captures the requirements.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot8309,
  title = {Test-Driven Development and LLM-based Code Generation},
  author = {Noble Saji Mathews and Meiyappan Nagappan},
  booktitle = {ASE},
  year = {2024},
  doi = {10.1145/3691620.3695527}
}