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

使用预训练大语言模型和变异测试的有效测试生成

Effective Test Generation Using Pre-trained Large Language Models and Mutation Testing

Arghavan Moradi Dakhel, Amin Nikanjam, Vahid Majdinasab, Foutse Khomh, Michel C. Desmarais

AI总结:

本文提出MuTAP方法,利用变异测试增强大语言模型生成测试用例的缺陷检测能力,在多个基准上检测出更多缺陷,并达到93.57%的变异得分。

摘要:

软件开发中的关键阶段之一是软件测试。测试有助于识别潜在缺陷并降低维护成本。自动化测试生成工具的目标是通过建议高效的缺陷揭示测试来简化测试的开发。最近,研究人员利用代码大语言模型(LLMs)生成单元测试。虽然通常评估生成测试的代码覆盖率,但文献已承认覆盖率与测试在缺陷检测中的效率相关性较弱。为改进此局限性,本文引入MuTAP,通过利用变异测试来提高LLMs生成的测试用例在揭示缺陷方面的有效性。我们的目标是通过向提示中添加存活变异体来实现,因为这些变异体突出了测试用例在检测缺陷方面的局限性。MuTAP能够在缺乏被测程序(PUTs)自然语言描述的情况下生成有效的测试用例。我们在MuTAP中使用不同的LLMs,并评估它们在多个基准上的性能。结果表明,我们提出的方法能够检测出多达28%更多的有缺陷的人工编写代码片段。其中,17%的缺陷是当前最先进的完全自动化测试生成工具(即Pynguin)以及LLMs上的零样本/少样本学习方法均未检测到的。此外,MuTAP在合成错误代码上达到了93.57%的变异得分(MS),优于我们评估中的所有其他方法。我们的研究结果表明,尽管LLMs可以作为生成测试用例的有用工具,但它们需要特定的后处理步骤来增强生成测试用例的有效性,这些测试用例可能存在语法或功能错误,并且在检测某些类型的缺陷和测试边界情况PUTs方面可能无效。

英文摘要:

One of the critical phases in software development is software testing. Testing helps with identifying potential bugs and reducing maintenance costs. The goal of automated test generation tools is to ease the development of tests by suggesting efficient bug-revealing tests. Recently, researchers have leveraged Large Language Models (LLMs) of code to generate unit tests. While the code coverage of generated tests was usually assessed, the literature has acknowledged that the coverage is weakly correlated with the efficiency of tests in bug detection. To improve over this limitation, in this paper, we introduce MuTAP for improving the effectiveness of test cases generated by LLMs in terms of revealing bugs by leveraging mutation testing. Our goal is achieved by augmenting prompts with surviving mutants, as those mutants highlight the limitations of test cases in detecting bugs. MuTAP is capable of generating effective test cases in the absence of natural language descriptions of the Program Under Test (PUTs). We employ different LLMs within MuTAP and evaluate their performance on different benchmarks. Our results show that our proposed method is able to detect up to 28% more faulty human-written code snippets. Among these, 17% remained undetected by both the current state-of-the-art fully automated test generation tool (i.e., Pynguin) and zero-shot/few-shot learning approaches on LLMs. Furthermore, MuTAP achieves a Mutation Score (MS) of 93.57% on synthetic buggy code, outperforming all other approaches in our evaluation. Our findings suggest that although LLMs can serve as a useful tool to generate test cases, they require specific post-processing steps to enhance the effectiveness of the generated test cases which may suffer from syntactic or functional errors and may be ineffective in detecting certain types of bugs and testing corner cases PUTs.

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

↑