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被提出。然而,由于缺乏断言知识与测试签名验证,AthenaTest仅有不到五分之一的测试用例能被正确生成。本文提出A3Test,一种基于深度学习的测试用例生成方法,通过断言知识增强,并引入命名一致性与测试签名验证机制。A3Test利用领域自适应原理,旨在将断言生成任务的现有知识迁移至测试用例生成任务。我们还提出一种验证方法,用于检验命名一致性与测试签名。通过在Defects4j数据集的5,278个焦点方法上的评估,我们发现:与AthenaTest相比,A3Test (1) 生成了更多正确的测试用例(增加147%)和更高的方法覆盖率(提升15%),同时生成测试用例总数更少;(2) 在测试用例生成任务上仍优于现有预训练模型;(3) 通过提出的断言预训练与验证组件对性能提升贡献显著;(4) 准确率更高且速度快97.2%。