Assessing Mock Classes: An Empirical Study (ICSME 2020)
andrehoraa
22 views
51 slides
Jul 25, 2024
Slide 1 of 51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
About This Presentation
During testing activities, developers frequently rely on dependencies (e.g., web services, etc) that make the test harder to be implemented. In this scenario, they can use mock objects to emulate the dependencies' behavior, which contributes to make the test fast and isolated. In practice, the e...
During testing activities, developers frequently rely on dependencies (e.g., web services, etc) that make the test harder to be implemented. In this scenario, they can use mock objects to emulate the dependencies' behavior, which contributes to make the test fast and isolated. In practice, the emulated dependency can be dynamically created with the support of mocking frameworks or manually hand-coded in mock classes. While the former is well-explored by the research literature, the latter has not yet been studied. Assessing mock classes would provide the basis to better understand how those mocks are created and consumed by developers and to detect novel practices and challenges. In this paper, we provide the first empirical study to assess mock classes. We analyze 12 popular software projects, detect 604 mock classes, and assess their content, design, and usage. We find that mock classes: often emulate domain objects, external dependencies, and web services; are typically part of a hierarchy; are mostly public, but 1/3 are private; and are largely consumed by client projects, particularly to support web testing. Finally, based on our results, we provide implications and insights to researchers and practitioners working with mock classes.
Size: 1.79 MB
Language: en
Added: Jul 25, 2024
Slides: 51 pages
Slide Content
Motivation
Mocks are frequently used in software testing
Mocks simulate dependencies making tests fast, isolated and
deterministic
Two ways to use mocks: mock objects and mock classes
Mock objects
Object creation based on mocking frameworks
“Canning” behavior/state based on a specification
EASYMOCK o / nibrest-noc
mockit Kress noce
Easy mocking. Better testing.
atomy of a mock object
@Test
public void t G r() {
Car car = mock(Car.class)
ar(any(Car.class)))
Return(car)
(null);