PROZE:基于运行时数据生成参数化单元测试
PROZE: Generating Parameterized Unit Tests Informed by Runtime Data
AI总结:
本文提出 PROZE 系统,通过运行时收集 CUT 中目标方法的多种输入并识别可泛化的开发者断言,自动生成参数化单元测试,在 5 个 Java 模块上生成 2,287 个 PUT,证明其中 217 个的预言在更大输入范围内成立。
摘要:
通常,传统单元测试(CUT)通过一个特定的输入/输出对来验证被测单元的预期行为。相比之下,参数化单元测试(PUT)接收一组输入作为参数,并包含期望对所有输入都成立的断言。PUT 提高了测试质量,因为它们在广泛的输入和行为范围内评估正确性。然而,为一组输入定义断言对开发者来说是一项困难的任务,这限制了 PUT 在实践中被采用。在本文中,我们解决为 PUT 寻找在多个输入上成立的测试预言(oracle)的问题。我们设计了一个名为 PROZE 的系统,该系统通过识别开发者编写的、对多个测试输入有效的断言来生成 PUT。我们将我们的方法实现为一个两步方法论:首先,在运行时,我们为在 CUT 中被调用的目标方法收集输入;接下来,我们隔离 CUT 中有效的断言,以便在 PUT 中使用。我们针对 5 个真实世界的 Java 模块评估了我们的方法,并从测试执行和现场执行中为 128 个目标方法收集了有效输入。我们生成了 2,287 个 PUT,这些 PUT 使用比原始 CUT 显著更多的测试输入来调用目标方法。我们执行了这些 PUT,并发现其中 217 个可证明地展示了它们的测试预言在比开发者设想的更大输入范围内成立。从测试理论的角度来看,我们的结果表明,开发者在 CUT 中表达的断言具有足够的通用性,可以超越某一特定输入而成立。
英文摘要:
Typically, a conventional unit test (CUT) verifies the expected behavior of the unit under test through one specific input / output pair. In contrast, a parameterized unit test (PUT) receives a set of inputs as arguments, and contains assertions that are expected to hold true for all these inputs. PUTs increase test quality, as they assess correctness on a broad scope of inputs and behaviors. However, defining assertions over a set of inputs is a hard task for developers, which limits the adoption of PUTs in practice. In this paper, we address the problem of finding oracles for PUTs that hold over multiple inputs. We design a system called PROZE, that generates PUTs by identifying developer-written assertions that are valid for more than one test input. We implement our approach as a two-step methodology: first, at runtime, we collect inputs for a target method that is invoked within a CUT; next, we isolate the valid assertions of the CUT to be used within a PUT. We evaluate our approach against 5 real-world Java modules, and collect valid inputs for 128 target methods from test and field executions. We generate 2,287 PUTs, which invoke the target methods with a significantly larger number of test inputs than the original CUTs. We execute the PUTs and find 217 that provably demonstrate that their oracles hold for a larger range of inputs than envisioned by the developers. From a testing theory perspective, our results show that developers express assertions within CUTs that are general enough to hold beyond one particular input.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。