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