paperbot · PL 论文追踪

全部论文 待读 收藏

P2 On learning meaningful assert statements for unit test cases

面向单元测试用例的有意义断言语句学习
ICSE Proceedings of the ACM/IEEE 42nd International Conference on Software Engineering2020匹配度 2/10 · 该论文属于机器学习用于软件测试/断言生成,与用户关注的静态分析、Agentic 程序、浮点程序分析、贝叶斯程序分析及 LLM 改进静态分析/形式化验证无直接关系;方法基于神经机器翻译而非当前强模型或 Agent,且不涉及形式化或工业静态分析落地。引用 106 inbox
Cody Watson, Michele Tufano, Kevin Moran, Gabriele Bavota, Denys Poshyvanyk
crossref: 2026-09-12

AI 速览

一句话:提出基于神经机器翻译的 Atlas 方法,自动为测试方法生成有意义的断言语句。

软件测试耗时且自动生成测试方法中的断言质量常受质疑。本文提出 Atlas(AuTomatic Learning of Assert Statements),一种基于神经机器翻译的方法:给定测试方法和被测焦点方法,预测用于评估焦点方法正确性的有意义断言语句。作者从 GitHub 项目收集数千个测试方法进行训练与评估,在仅考虑 top-1 预测断言时,31% 的案例能精确匹配开发者手写断言;考虑 top-5 时精确匹配率达到 50%。结果表明,该方法可作为自动测试用例生成技术的补充,也可为开发者在编写测试代码时提供断言补全支持。

问题
自动生成测试方法中的断言语句常缺乏质量与实用性,如何为给定测试方法和焦点方法自动生成有意义的断言。
方法
采用基于神经机器翻译(NMT)的 Atlas 方法,从测试方法及焦点方法中学习并预测断言语句。
评估
在 GitHub 项目的数千个测试方法上评估,报告 top-1 和 top-5 预测与开发者手写断言的精确匹配率,分别为 31% 和 50%。
原文摘要(Abstract)

Software testing is an essential part of the software lifecycle and requires a substantial amount of time and effort. It has been estimated that software developers spend close to 50% of their time on testing the code they write. For these reasons, a long standing goal within the research community is to (partially) automate software testing. While several techniques and tools have been proposed to automatically generate test methods, recent work has criticized the quality and usefulness of the assert statements they generate. Therefore, we employ a Neural Machine Translation (NMT) based approach called Atlas (AuTomatic Learning of Assert Statements) to automatically generate meaningful assert statements for test methods. Given a test method and a focal method (i.e., the main method under test), Atlas can predict a meaningful assert statement to assess the correctness of the focal method. We applied Atlas to thousands of test methods from GitHub projects and it was able to predict the exact assert statement manually written by developers in 31% of the cases when only considering the top-1 predicted assert. When considering the top-5 predicted assert statements, Atlas is able to predict exact matches in 50% of the cases. These promising results hint to the potential usefulness of our approach as (i) a complement to automatic test case generation techniques, and (ii) a code completion support for developers, who can benefit from the recommended assert statements while writing test code.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@inproceedings{paperbot5600,
  title = {On learning meaningful assert statements for unit test cases},
  author = {Cody Watson and Michele Tufano and Kevin Moran and Gabriele Bavota and Denys Poshyvanyk},
  booktitle = {ICSE},
  year = {2020},
  doi = {10.1145/3377811.3380429}
}