一句话:提出测试补全任务,并设计利用代码执行语义的深度学习模型 TECO,自动补全测试方法中的下一条语句。
测试编写耗时但关键。论文提出用深度学习辅助编写测试,并形式化新任务“测试补全”:根据测试方法已有语句和被测代码,自动补全下一条语句。作者提出 TECO 模型,核心观点是预测下一条语句需要推理代码执行,仅靠语法级数据难以完成;TECO 抽取并使用六类代码语义数据,包括先前语句的执行结果和测试方法的执行上下文。评估使用从 1,270 个开源 Java 项目收集的 130,934 个测试方法。结果显示,TECO 精确匹配准确率为 18%,比仅用语法数据的最佳基线高 29%;生成语句在 29% 情况下可运行,而最佳基线为 18%;在测试 oracle 生成上亦显著优于先前工作。
Writing tests is a time-consuming yet essential task during software development. We propose to leverage recent advances in deep learning for text and code generation to assist developers in writing tests. We formalize the novel task of test completion to automatically complete the next statement in a test method based on the context of prior statements and the code under test. We develop TECo-a deep learning model using code semantics for test completion. The key insight underlying TECO is that predicting the next statement in a test method requires reasoning about code execution, which is hard to do with only syntax-level data that existing code completion models use. Teco extracts and uses six kinds of code semantics data, including the execution result of prior statements and the execution context of the test method. To provide a testbed for this new task, as well as to evaluate TECO, we collect a corpus of 130,934 test methods from 1,270 open-source Java projects. Our results show that Teco achieves an exact-match accuracy of 18, which is 29% higher than the best baseline using syntax-level data only. When measuring functional correctness of generated next statement, Teco can generate runnable code in 29% of the cases compared to 18% obtained by the best baseline. Moreover, Teco is sianificantly better than prior work on test oracle generation.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{abs-2302-10166,
title = {Learning Deep Semantics for Test Completion},
author = {Pengyu Nie and Rahul Banerjee and Junyi Jessy Li and Raymond J. Mooney and Milos Gligoric},
booktitle = {ICSE},
year = {2023},
doi = {10.1109/icse48619.2023.00178}
}