Skip to main content
QUICK REVIEW

[论文解读] TESTEVAL: Benchmarking Large Language Models for Test Case Generation

Wenhan Wang, Chenyuan Yang|arXiv (Cornell University)|Jun 6, 2024
Software Testing and Debugging TechniquesComputer Science被引用 3
一句话总结

本论文提出了TestEval,一个用于评估大语言模型(LLMs)在Python程序测试用例生成中表现的基准。该研究在三个任务——整体覆盖、目标行/分支覆盖以及目标路径覆盖——上评估了16个LLMs,结果表明当前LLMs在程序逻辑理解方面存在困难,尤其是在目标覆盖任务中表现不佳,尽管其在一般测试用例多样性方面表现良好。

ABSTRACT

Testing plays a crucial role in the software development cycle, enabling the detection of bugs, vulnerabilities, and other undesirable behaviors. To perform software testing, testers need to write code snippets that execute the program under test. Recently, researchers have recognized the potential of large language models (LLMs) in software testing. However, there remains a lack of fair comparisons between different LLMs in terms of test case generation capabilities. In this paper, we propose TESTEVAL, a novel benchmark for test case generation with LLMs. We collect 210 Python programs from an online programming platform, LeetCode, and design three different tasks: overall coverage, targeted line/branch coverage, and targeted path coverage. We further evaluate sixteen popular LLMs, including both commercial and open-source ones, on TESTEVAL. We find that generating test cases to cover specific program lines/branches/paths is still challenging for current LLMs, indicating a lack of ability to comprehend program logic and execution paths. We have open-sourced our dataset and benchmark pipelines at https://github.com/LLM4SoftwareTesting/TestEval.

研究动机与目标

  • 解决自动化测试用例生成中LLMs评估缺乏标准化基准的问题。
  • 探究LLMs是否能够生成测试用例以实现高整体覆盖度,或针对特定代码行/分支,或遵循特定执行路径。
  • 提供一个公开且可复现的基准,以加速基于LLM的软件测试研究。
  • 比较商业模型与开源模型在生成语义正确且以覆盖为导向的测试用例方面的能力。
  • 识别LLM在测试生成过程中理解程序逻辑时的推理局限性。

提出的方法

  • 从LeetCode收集210个Python程序作为基准数据集。
  • 设计了三种不同的测试用例生成任务:整体覆盖、目标行/分支覆盖以及目标路径覆盖。
  • 为每项任务构建了标准化的提示模板,以确保所有模型的输入一致。
  • 实施了两阶段正确性检查:语法验证和通过程序执行进行的执行测试。
  • 使用覆盖度指标(语句、分支、路径)来评估测试用例的有效性。
  • 在相同条件下评估了16个LLMs,包括商业模型(如GPT-4)和开源模型(如Llama、DeepSeek、Qwen)。
Figure 1: The pipeline for running and evaluating LLMs for test case generation on TestEval .
Figure 1: The pipeline for running and evaluating LLMs for test case generation on TestEval .

实验结果

研究问题

  • RQ1LLMs能否生成多样化且可执行的测试用例,以实现高整体代码覆盖度?
  • RQ2LLMs在多大程度上能够根据自然语言指令生成针对特定程序行或分支的测试用例?
  • RQ3LLMs能否生成符合测试人员预期的特定执行路径的测试用例?
  • RQ4商业LLMs与开源LLMs在生成覆盖导向测试用例方面的能力有何差异?
  • RQ5LLM在测试用例生成过程中理解程序逻辑时,其推理能力的主要局限是什么?

主要发现

  • 商业LLMs如GPT-4在整体覆盖和目标覆盖任务中均优于开源模型。
  • 在目标行覆盖任务中,即使提供了目标行信息,16个LLMs中有12个的性能提升不超过5%,表明其对程序逻辑的理解能力较差。
  • 在目标路径覆盖任务中,性能提升微乎其微(例如,DeepSeek-33B仅提升2.73%),表明LLMs在路径感知测试生成方面存在困难。
  • 尽管语法正确率很高(如CodeQwen-7B达到99.77%),但许多模型在复杂逻辑下仍无法生成功能正确的测试用例。
  • 像Mistral-0.3和较小的开源LLMs表现较差,其路径覆盖度低于33%,行覆盖度低于23%。
  • 该基准揭示了LLMs在推理控制流和执行路径方面存在持续性差距,即使在提供详细描述的情况下也难以改善。
Figure 2: An example for selecting targeted lines and branches from programs under test.
Figure 2: An example for selecting targeted lines and branches from programs under test.

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。