Skip to main content
QUICK REVIEW

[论文解读] A3Test: Assertion-Augmented Automated Test Case Generation

Saranya Alagarsamy, Chakkrit Tantithamthavorn|arXiv (Cornell University)|Feb 20, 2023
Software Engineering Research被引用 6
一句话总结

A3Test 是一种基于深度学习的测试用例生成方法,通过领域自适应预训练整合断言知识,并引入验证模块以确保命名一致性和测试签名正确性,相比 AthenaTest,其正确测试用例数量提升 147%,方法覆盖率提高 15%,同时速度快 97.2%,并优于现有预训练模型。

ABSTRACT

Test case generation is an important activity, yet a time-consuming and laborious task. Recently, AthenaTest -- a deep learning approach for generating unit test cases -- is proposed. However, AthenaTest can generate less than one-fifth of the test cases correctly, due to a lack of assertion knowledge and test signature verification. In this paper, we propose A3Test, a DL-based test case generation approach that is augmented by assertion knowledge with a mechanism to verify naming consistency and test signatures. A3Test leverages the domain adaptation principles where the goal is to adapt the existing knowledge from an assertion generation task to the test case generation task. We also introduce a verification approach to verify naming consistency and test signatures. Through an evaluation of 5,278 focal methods from the Defects4j dataset, we find that our A3Test (1) achieves 147% more correct test cases and 15% more method coverage, with a lower number of generated test cases than AthenaTest; (2) still outperforms the existing pre-trained models for the test case generation task; (3) contributes substantially to performance improvement via our own proposed assertion pre-training and the verification components; (4) is 97.2% much faster while being more accurate than AthenaTest.

研究动机与目标

  • 为解决 AthenaTest 的局限性,即因缺乏断言知识和签名验证而导致生成错误断言和语法无效的测试用例。
  • 通过利用从断言生成到测试用例生成的领域自适应,采用自监督预训练方法,提升测试用例质量。
  • 通过验证命名一致性与测试签名合规性(如 public、void、@Test 注解等),提升测试用例的可读性和正确性。
  • 评估断言预训练和验证组件在提升测试用例生成性能方面的有效性。
  • 证明 A3Test 在正确性、覆盖率和效率方面优于 AthenaTest 和现有预训练模型。

提出的方法

  • A3Test 使用基于 PLBART 的架构,在断言生成任务上通过掩码语言建模进行预训练,以构建强大的断言知识。
  • 通过翻译式任务对预训练模型进行微调,即从焦点方法的输入映射到开发人员编写的测试用例,用于测试用例生成。
  • 生成后增加验证模块,检查并修正测试方法名称,确保其与焦点方法一致,并确保测试签名正确(如补全缺失的 'public' 或 '@Test' 注解)。
  • 该方法利用领域自适应,将断言生成的知识迁移至测试用例生成,提升语义和语法正确性。
  • 模型在 Defects4j 数据集的 5,278 个焦点方法上进行训练和评估,涵盖五个开源项目(Lang、Chart、Cli、Csv、Gson)。
  • 报告了超参数设置,以确保可复现性,并降低复制研究中的内部有效性威胁。

实验结果

研究问题

  • RQ1RQ1:A3Test 在正确性和方法覆盖率方面与 AthenaTest 相比如何?
  • RQ2RQ2:所提出的断言预训练和验证机制是否显著提升了测试用例生成性能?
  • RQ3RQ3:A3Test 在测试用例生成方面与其它预训练模型(如 CodeBERT、CodeT5、PLBART)相比表现如何?
  • RQ4RQ4:与 AthenaTest 相比,A3Test 的速度和效率如何?

主要发现

  • A3Test 相比 AthenaTest 实现了 147% 更多的正确测试用例,在作者复现实验中,正确率提升至 18.08%,而 AthenaTest 为 0%。
  • A3Test 在生成更少测试用例的情况下,将方法覆盖率提高了 15%,表明其效率更高。
  • 验证组件通过修正命名不一致和补全 'public' 或 '@Test' 等缺失关键字,显著减少了语法错误。
  • A3Test 在测试用例生成准确率方面优于现有预训练模型,如 PLBART、CodeGPT、CodeBERT 和 CodeT5。
  • A3Test 在保持更高准确率的同时,比 AthenaTest 快 97.2%,展现出显著的性能提升。
  • 断言预训练组件对性能有显著贡献,表现为错误断言减少(如 assertEquals 中参数数量错误等)。

更好的研究,从现在开始

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

无需绑定信用卡

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