Skip to main content
QUICK REVIEW

[论文解读] Prompting Code Interpreter to Write Better Unit Tests on Quixbugs Functions

V.O.K. Li, Nick Doiron|arXiv (Cornell University)|Sep 30, 2023
Software Engineering Research被引用 4
一句话总结

本研究探讨了不同提示策略对基于 GPT-4 的 Code Interpreter 模型在 Quixbugs 数据集中函数上生成单元测试质量的影响。尽管提示格式、示例或注释存在差异,测试质量基本保持不变;然而,该模型频繁地自我修正其生成的代码,表明启用可执行反馈循环能显著提升可靠性与输出正确性。

ABSTRACT

Unit testing is a commonly-used approach in software engineering to test the correctness and robustness of written code. Unit tests are tests designed to test small components of a codebase in isolation, such as an individual function or method. Although unit tests have historically been written by human programmers, recent advancements in AI, particularly LLMs, have shown corresponding advances in automatic unit test generation. In this study, we explore the effect of different prompts on the quality of unit tests generated by Code Interpreter, a GPT-4-based LLM, on Python functions provided by the Quixbugs dataset, and we focus on prompting due to the ease with which users can make use of our findings and observations. We find that the quality of the generated unit tests is not sensitive to changes in minor details in the prompts provided. However, we observe that Code Interpreter is often able to effectively identify and correct mistakes in code that it writes, suggesting that providing it runnable code to check the correctness of its outputs would be beneficial, even though we find that it is already often able to generate correctly-formatted unit tests. Our findings suggest that, when prompting models similar to Code Interpreter, it is important to include the basic information necessary to generate unit tests, but minor details are not as important.

研究动机与目标

  • 评估提示变化对 Code Interpreter 在真实世界 Python 函数上生成单元测试质量的影响。
  • 确定微小的提示修改(如格式、示例或角色指令)是否会影响测试的正确性与完整性。
  • 评估模型检测并修正其自身生成测试代码中错误的能力。
  • 识别在单元测试生成中对开发者有效且实用的 LLM 提示最佳实践。
  • 探索通过可执行反馈提升测试生成质量的可行性,而无需迭代式提示。

提出的方法

  • 本研究使用 Code Interpreter(基于 GPT-4 的模型)为 Quixbugs 数据集中的函数生成单元测试,该数据集专为自动化测试设计。
  • 系统性地改变提示的格式:代码上下文以原始代码或自然语言描述形式呈现,是否包含格式化示例和基于角色的注释。
  • 在受控环境中执行生成的单元测试,以评估其正确性、编译成功率和断言准确性。
  • 通过运行模型自身生成的代码并分析错误是否在后续生成中被检测并修复,评估模型的自我修正能力。
  • 基于与简单输入/输出测试框架的兼容性,选取部分函数以确保可执行评估。
  • 每条提示生成多个版本,以提高获得正确、可编译测试套件的可能性。

实验结果

研究问题

  • RQ1提示格式的变化(如代码与自然语言上下文)如何影响生成单元测试的质量?
  • RQ2包含格式化示例或基于角色的注释(如“扮演专家程序员”)是否显著提升测试质量?
  • RQ3Code Interpreter 在多大程度上能够检测并修正其自身生成的单元测试中的错误?
  • RQ4与静态提示相比,引入可执行反馈(即运行代码)如何影响测试生成的可靠性?
  • RQ5在使用 Code Interpreter 生成正确、可编译且全面的单元测试时,最有效的提示策略是什么?

主要发现

  • Code Interpreter 生成的单元测试质量对提示的微小变化(如格式风格、示例或角色注释的包含)基本不敏感。
  • 尽管提示变化影响极小,Code Interpreter 频繁地自我修正其代码,表明其具备强大的内部一致性与错误检测能力。
  • 该模型在无需额外提示以规范结构的情况下,已能高效生成语法正确且格式规范的单元测试。
  • 启用模型执行其自身输出可显著提升可靠性,表明集成可运行反馈循环能增强测试质量。
  • 即使在提供极少或模糊上下文的情况下,该模型生成正确测试的能力依然稳健,表明其从训练数据中具备强大的泛化能力。
  • 本研究指出,未来改进的重点应放在反馈机制上,而非针对格式细节的提示工程。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。