arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2503.08182cs.SE
收藏

通过迭代式大语言模型驱动的科学调试进行变异测试

Mutation Testing via Iterative Large Language Model-Driven Scientific Debugging

Philipp Straubinger, Marvin Kreis, Stephan Lukasczyk, Gordon Fraser

AI总结:

本文提出利用科学调试方法让大语言模型通过迭代假设与改进来生成针对变异体的测试,实验表明其缺陷检测能力和覆盖率均优于Pynguin等基线方法。

摘要:

大语言模型(LLMs)能够生成看似合理的测试代码。直观上,它们是通过模仿训练数据中见过的测试来生成代码,而不是对执行语义进行推理。然而,在应用变异测试时,这种推理非常重要,因为变异测试要求每个测试能够展示程序与特定人工缺陷(变异体)之间的行为差异。在本文中,我们评估了科学调试(Scientific Debugging)——该方法已被证明在调试时能帮助大语言模型——是否也能帮助它们为变异体生成测试。在所提出的方法中,大语言模型对如何杀死特定变异体形成假设,然后迭代地生成并改进测试,直到成功为止,每一步都附带详细的解释。我们将该方法与三个基线进行比较:(1)直接要求大语言模型生成测试,(2)在测试失败时反复查询大语言模型,以及(3)使用Pynguin进行基于搜索的测试生成。我们的实验从多个因素评估这些方法,包括变异得分、代码覆盖率、成功率以及识别等价变异体的能力。结果表明,尽管大语言模型需要更高的计算成本,但在生成具有更好缺陷检测能力和覆盖率的测试方面,始终优于Pynguin。重要的是,我们观察到测试用例的迭代改进对于获得高质量测试套件至关重要。

英文摘要:

Large Language Models (LLMs) can generate plausible test code. Intuitively they generate this by imitating tests seen in their training data, rather than reasoning about execution semantics. However, such reasoning is important when applying mutation testing, where individual tests need to demonstrate differences in program behavior between a program and specific artificial defects (mutants). In this paper, we evaluate whether Scientific Debugging, which has been shown to help LLMs when debugging, can also help them to generate tests for mutants. In the resulting approach, LLMs form hypotheses about how to kill specific mutants, and then iteratively generate and refine tests until they succeed, all with detailed explanations for each step. We compare this method to three baselines: (1) directly asking the LLM to generate tests, (2) repeatedly querying the LLM when tests fail, and (3) search-based test generation with Pynguin. Our experiments evaluate these methods based on several factors, including mutation score, code coverage, success rate, and the ability to identify equivalent mutants. The results demonstrate that LLMs, although requiring higher computation cost, consistently outperform Pynguin in generating tests with better fault detection and coverage. Importantly, we observe that the iterative refinement of test cases is important for achieving high-quality test suites.

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

↑