名称即所需:Python 有效且安全的回归测试选择
Names Are All You Need: Effective and Safe Regression Test Selection for Python
AI总结:
提出基于细粒度依赖分析的 Python 回归测试选择方法 NameRTS,通过将程序建模为二分图并求解可达性问题,在保持安全性的同时显著提升测试跳过率。
摘要:
回归测试选择通过仅执行受代码变更影响的测试来降低回归测试成本。尽管在静态类型语言中已对 RTS 进行了广泛研究,但在 Python 中实现有效且安全的 RTS 仍具挑战性。Python 的动态类型使得精确调用图构建困难,这可能导致基于调用图的 RTS 遗漏受影响的测试。相反,Python 的急切导入机制使得文件级依赖分析过于保守。本文提出 NameRTS,首个基于细粒度依赖分析的 Python RTS 方法。NameRTS 将 Python 程序建模为代码元素节点和名称节点构成的二分图,边捕获定义和引用关系。RTS 被形式化为该图上的可达性问题:如果任何被修改的代码元素可从该测试中使用的名称到达,则选择该测试。这种设计避免了调用图构建,使得保守分析能够保证安全性。为控制粗粒度名称匹配引入的依赖级联,NameRTS 应用两种剪枝策略,利用先前的测试执行和上下文信息来细化名称匹配。为评估 NameRTS,我们构建了首个 Python RTS 数据集,其中包含每个提交受影响的测试文件的地面真值。我们将 NameRTS 与性能最佳的基线 BabelRTS(一种基于粗粒度文件级依赖的 RTS 技术)进行比较。在该基准上,NameRTS 平均跳过 69.90% 的测试文件,优于 BabelRTS 146.5%。它还减少了 45.59% 的端到端测试时间,比 BabelRTS 提高了 107.7%。在安全性方面,NameRTS 为 99.6% 的提交选择了所有受影响的测试,仅在极少数情况下出现遗漏。相比之下,BabelRTS 对 76.6% 的提交是安全的。这些结果证明了 NameRTS 的有效性,为 Python 中更高效的回归测试铺平了道路。
英文摘要:
Regression test selection reduces the cost of regression testing by executing only those tests affected by a code change. Despite extensive study of RTS in statically typed languages, achieving effective and safe RTS in Python is challenging. Python's dynamic typing makes precise call-graph construction difficult, which can cause call-graph-based RTS to miss affected tests. Python's eager importing mechanism, in contrast, renders file-level dependency analysis overly conservative. This paper presents NameRTS, the first Python RTS approach based on fine-grained dependency analysis. NameRTS models a Python program as a bipartite graph of code element nodes and name nodes, with edges capturing definitions and references. RTS is formulated as a reachability problem on this graph: a test is selected if any modified code element is reachable from the names used in that test. This design avoids call-graph construction, enabling a conservative analysis amenable to safety. To control dependency cascades introduced by coarse name matching, NameRTS applies two pruning strategies that leverage prior test executions and context information to refine name matching. To evaluate NameRTS, we construct the first Python RTS dataset with a ground truth indicating which test files are affected by each commit. We compare NameRTS with the best-performing baseline, BabelRTS, an RTS technique based on coarse file-level dependencies. On this benchmark, NameRTS skips 69.90% of test files on average, outperforming BabelRTS by 146.5%. It also reduces end-to-end testing time by 45.59%, yielding a 107.7% improvement over BabelRTS. In terms of safety, NameRTS selects all affected tests for 99.6% of commits, with only rare misses in exceptional cases. In contrast, BabelRTS is safe for 76.6% of commits. These results demonstrate the effectiveness of NameRTS, paving the way for more efficient regression testing in Python.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。