Mocking in the context of automated software tests allows testing program units in isolation. Designing realistic interactions between a unit and its environment, and understanding the expected impact of these interactions on the behavior of the unit, are two key challenges that software testers face when developing tests with mocks. 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 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. Next, RICK analyzes the production observations in order to generate test cases that include rich initial states and test inputs, mocks and stubs that recreate actual interactions between the method and its environment, as well as mock-based oracles. All the test cases are executable, and 52.4% of them successfully mimic the complete execution context of the target methods observed in production. We interview 5 developers from the industry who confirm the relevance of using production observations to design mocks and stubs.
翻译:在自动软件测试中进行模拟,可以孤立地测试程序单位。设计一个单位及其环境之间的现实互动,并理解这些互动对单位行为的预期影响,这是软件测试者在开发模拟测试时所面临的两大挑战。在本文中,我们提议监测生产中的应用,以产生模拟现实执行情景的测试。我们的方法分三个阶段运作。首先,我们用一套我们想要生成测试的目标方法以及它们所使用的方法,我们指的是可模拟的方法。第二,在制作过程中,我们收集关于目标方法的使用背景的数据,以及每个可模拟方法呼吁的参数和返回值。第三,我们不在线地分析生产数据,以模拟投入和模拟互动的方式生成测试案例。我们用三种真实世界、开放源的爪哇应用来评估我们的方法。RICK监测了在三个应用程序中采用128种方法的情况,并记录了它们的行为。接下来,RICK从模拟生产中分析生产数据,用现实的测试案例,或者在模拟生产中进行测试案例的模拟测试,包括模拟测试环境的模拟数据,以及模拟数据,测试所有模拟的模拟数据,包括模拟数据、模拟数据、模拟数据、模拟数据、模拟数据、模拟数据、模拟、模拟、模拟程序、模拟数据、模拟数据、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、模拟、