paperbot · PL 论文追踪

全部论文 待读 收藏

P2 An Empirical Evaluation of Property-Based Testing in Python

Python 中基于属性的测试的实证评估
OOPSLA 9(OOPSLA2)2025匹配度 2/10 · 论文研究 Python 属性测试的有效性,虽然使用了静态分析来分类测试,但目标场景是普通 Python 测试而非 ML/Agentic 程序,也未涉及 LLM、浮点程序分析或贝叶斯程序分析。因此与用户研究方向核心不匹配,仅可视为方法上略有交集的存档文献。引用 2 inbox
Savitha Ravi, Michael Coblenz
crossref: 2026-09-10

AI 速览

一句话:通过 426 个 Hypothesis 程序语料与变异测试,实证评估 Python 中基于属性的测试的找错效果及影响因素。

基于属性的测试(PBT)源自函数式编程社区,近年来也被引入 Python 等非函数式语言,但其发现缺陷的有效性以及不同测试类别的相对效果仍缺乏证据。本文针对使用 Hypothesis 的 426 个 Python 程序开展语料库研究,为 12 类基于属性的测试给出形式定义,并实现过程内静态分析对测试分类。随后,作者用变异测试评估 40 个项目的测试套件,发现平均每个 PBT 发现的变异体约为普通单元测试的 50 倍;其中查找异常、测试集合包含和检查类型的测试比其他 PBT 有效 19 倍以上。参数扫描还表明,76% 的被发现变异体在前 20 个随机输入内即可发现。

问题
PBT 已从函数式编程社区扩展到 Python,但缺乏证据说明其发现缺陷的有效性,以及哪些类别的 PBT 更有效。
方法
对 426 个使用 Hypothesis 的 Python 程序进行语料库研究,定义 12 类 PBT 并实现过程内静态分析分类;对 40 个项目使用变异测试和参数扫描评估效果。
评估
通过变异测试比较 PBT 与单元测试的发现变异体能力,并对随机输入数量进行参数扫描。
原文摘要(Abstract)

Property-based testing (PBT) is a testing methodology with origins in the functional programming community. In recent years, PBT libraries have been developed for non-functional languages, including Python. However, to date, there is little evidence regarding how effective property-based tests are at finding bugs, and whether some kinds of property-based tests might be more effective than others. To gather this evidence, we conducted a corpus study of 426 Python programs that use Hypothesis, Python’s most popular library for PBT. We developed formal definitions for 12 categories of property-based test and implemented an intraprocedural static analysis that categorizes tests. Then, we evaluated the efficacy of test suites of 40 projects using mutation testing, and found that on average, each property-based test finds about 50 times as many mutations as the average unit test. We also identified the categories with the tests most effective at finding mutations, finding that tests that look for exceptions, that test inclusion in collections, and that check types are over 19 times more effective at finding mutations than other kinds of property-based tests. Finally, we conducted a parameter sweep study to assess the strength of property-based tests as a function of the number of random inputs generated, finding that 76% of mutations found were found within the first 20 inputs.

链接与引用

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

BibTeX
@article{paperbot3014,
  title = {An Empirical Evaluation of Property-Based Testing in Python},
  author = {Savitha Ravi and Michael Coblenz},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {9},
  number = {OOPSLA2},
  year = {2025},
  doi = {10.1145/3764068}
}