paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Characterizing and Refactoring Table-Driven Tests in Go

Go 中表驱动测试的特征刻画与重构
ICSE Proceedings of the IEEE/ACM 48th International Conference on Software Engineering2026匹配度 2/10 · 论文研究 Go 表驱动测试的实证与自动重构,属于软件测试/程序变换,虽涉及自动化分析但未涉及 ML/Agent、LLM 与静态分析交叉、浮点程序分析或贝叶斯程序分析,与用户核心研究方向不匹配。引用 0 inbox
Max Green, Lu Xiao, Zhongpeng Lin
crossref: 2026-09-12

AI 速览

一句话:对 Go 表驱动测试开展实证研究,并提出自动化重构为缺少子测试的表驱动测试引入子测试。

表驱动测试是 Go 中广泛采用的测试风格:多个场景被编码在同一数据结构中并通过循环执行。然而,业界对其真实使用方式的理解仍然有限。本文对五个流行开源 Go 项目中的 8000 多个测试进行了试点研究,发现 31.7% 至 83.1% 的测试为表驱动,整体占比接近一半。基于检测到的模式,作者归纳出表驱动测试的常规结构,并识别出会损害可读性与执行控制的偏离形式。为解决这些问题,论文提出一种自动化重构技术,为缺少子测试的表驱动测试集成子测试。将该方法应用于 1100 多个符合条件的测试,成功率达到 69%,且除一例外均保持了原有行为。结果表明表驱动测试在 Go 中极为普遍,同时自动化改进以提升测试可读性、可维护性与标准化程度是可行的。

问题
目前对 Go 中表驱动测试在真实项目里如何实现缺乏系统认识,且许多测试的写法偏离常规结构,影响可读性与执行控制。
方法
对五个流行开源 Go 项目的 8000 多个测试进行实证分析,归纳表驱动测试的常规结构并识别偏离模式,进而实现自动化重构,为缺少子测试的表驱动测试引入子测试。
评估
在 1100 多个符合条件的测试上应用重构,成功率 69%,并且除一例外均保持行为不变。
原文摘要(Abstract)

Table-driven testing is a widely adopted style in Go, where multiple scenarios are encoded in a single data structure and executed in a loop. Despite its popularity, there is a limited understanding of how these tests are implemented in the real world. This paper presents a pilot study of table-driven tests across five popular open-source Go projects, comprising over 8,000 total tests. Our analysis indicates that between 31.7% and 83.1% of tests in these projects are table-driven, with an overall prevalence of nearly half. Based on detected patterns, we also identify a conventional structure for table-driven tests and observe deviations that hinder readability and execution control. To address these issues, we introduce an automated refactoring technique that integrates subtests into table-driven tests that lack them. Applied to over 1,100 eligible tests, our approach achieved a 69% success rate while preserving behavior in all but one case. These results highlight both the prevalence of table-driven testing in Go and the feasibility of automated improvements that make tests more readable, maintainable, and standardized.

链接与引用

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

BibTeX
@inproceedings{paperbot12056,
  title = {Characterizing and Refactoring Table-Driven Tests in Go},
  author = {Max Green and Lu Xiao and Zhongpeng Lin},
  booktitle = {ICSE},
  year = {2026},
  doi = {10.1145/3786582.3786837}
}