论文标题

通过生成的模拟模仿生产行为

Mimicking Production Behavior with Generated Mocks

论文作者

Tiwari, Deepika, Monperrus, Martin, Baudry, Benoit

论文摘要

模拟允许隔离测试程序单元。用模拟撰写测试的开发人员面临两个挑战:设计单位与其环境之间的现实互动;并了解这些相互作用对单位行为的预期影响。在本文中,我们建议监视生产中的应用程序,以生成通过模拟模仿现实执行方案的测试。我们的方法分为三个阶段。首先,我们启动了一组目标方法,我们要为其生成测试以及它们调用的方法,我们称之为模拟方法调用。其次,在生产中,我们收集有关调用目标方法的上下文以及每个模拟方法调用的参数和返回值的数据。第三,离线,我们分析生产数据以生成具有现实输入和模拟交互的测试用例。该方法是在称为Rick的开源工具中自动化和实现的。我们通过三个真实的开源Java应用程序评估了我们的方法。里克(Rick)在这三个应用程序中监视了128种生产方法的调用,并捕获了它们的行为。基于此捕获的数据,Rick生成了包括现实的初始状态和测试输入以及模拟和存根的测试用例。所有生成的测试用例都是可执行的,其中52.4%成功地模仿了生产中观察到的目标方法的完整执行环境。基于模拟的口腔也有效地检测目标方法中的回归,并以其故障找到能力相互补充。我们采访了5位来自该行业的开发人员,他们确认使用生产观察来设计模拟和存根的相关性。我们的实验发现清楚地证明了从生产相互作用中生成模拟的可行性和附加值。

Mocking allows testing program units in isolation. A developer who writes tests with mocks faces two challenges: design realistic interactions between a unit and its environment; and understand the expected impact of these interactions on the behavior of the unit. In this paper, we propose to monitor an application in production to generate tests that mimic realistic execution scenarios through mocks. Our approach operates in three phases. First, we instrument a set of target methods for which we want to generate tests, as well as the methods that they invoke, which we refer to as mockable method calls. Second, in production, we collect data about the context in which target methods are invoked, as well as the parameters and the returned value for each mockable method call. Third, offline, we analyze the production data to generate test cases with realistic inputs and mock interactions. The approach is automated and implemented in an open-source tool called RICK. We evaluate our approach with three real-world, open-source Java applications. RICK monitors the invocation of 128 methods in production across the three applications and captures their behavior. Based on this captured data, RICK generates test cases that include realistic initial states and test inputs, as well as mocks and stubs. All the generated test cases are executable, and 52.4% of them successfully mimic the complete execution context of the target methods observed in production. The mock-based oracles are also effective at detecting regressions within the target methods, complementing each other in their fault-finding ability. We interview 5 developers from the industry who confirm the relevance of using production observations to design mocks and stubs. Our experimental findings clearly demonstrate the feasibility and added value of generating mocks from production interactions.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源