To Mock Or Not To Mock? An Empirical Study on Mocking Practices - - PowerPoint PPT Presentation

to mock or not to mock
SMART_READER_LITE
LIVE PREVIEW

To Mock Or Not To Mock? An Empirical Study on Mocking Practices - - PowerPoint PPT Presentation

To Mock Or Not To Mock? An Empirical Study on Mocking Practices Davide Spadini , Mauricio Aniche, Magiel Bruntink, Alberto Bacchelli @DavideSpadini How do I test this? With dependencies Without dependencies Mock Unit under test Unit


slide-1
SLIDE 1

To Mock Or Not To Mock?

An Empirical Study on Mocking Practices

Davide Spadini, Mauricio Aniche, 
 Magiel Bruntink, Alberto Bacchelli @DavideSpadini

slide-2
SLIDE 2

How do I test this?

slide-3
SLIDE 3

With dependencies Without dependencies

slide-4
SLIDE 4

Mock

Unit under test Unit under test

slide-5
SLIDE 5
slide-6
SLIDE 6

With dependencies

slide-7
SLIDE 7

With dependencies

slide-8
SLIDE 8

With dependencies

slide-9
SLIDE 9
  • Faster
  • Easier

Without dependencies

slide-10
SLIDE 10

Without dependencies

You lose in reality, after all, it is just a simulation!

slide-11
SLIDE 11

To Mock Not to Mock

So, what should we do?

slide-12
SLIDE 12

RQ1: What test dependencies do developers mock? RQ2: Why do developers decide to (not) mock specific dependencies? RQ3: Which are the main challenges experienced with testing using mocks?

Research Questions

slide-13
SLIDE 13

Opensource Industrial

Methodology

slide-14
SLIDE 14

TA P1 Sonarqube Alura VRaptor Spring Framework TA P1 TA P1 TA P1

Methodology

slide-15
SLIDE 15

TA MockExtractor TA P3 Mock P1 P2

13,547 dependencies

P1 Sonarqube TA P3 Mock P1 P2

1,665 dependencies

Alura TA P3 Mock P1 P2

1,333 dependencies

VRaptor TA P3 Mock P1 P2

21,768 dependencies

Spring Framework TA P1 TA P1 TA P1

Methodology

slide-16
SLIDE 16

TA MockExtractor TA P3 Mock P1 P2

13,547 dependencies 674 dependencies

TA P1 Tn Pn … … Sampling P1 Sonarqube TA P3 Mock P1 P2

1,665 dependencies 445 dependencies

TA P1 Tn Pn … … Alura TA P3 Mock P1 P2

1,333 dependencies 438 dependencies

TA P1 Tn Pn … … VRaptor TA P3 Mock P1 P2

21,768 dependencies 621 dependencies

TA P1 Tn Pn … … Spring Framework

Data collection

TA P1 TA P1 TA P1

Methodology

slide-17
SLIDE 17

TA MockExtractor TA P3 Mock P1 P2

13,547 dependencies 674 dependencies

TA P1 Tn Pn … … Sampling

Sample 1

P1 Sonarqube TA P3 Mock P1 P2

1,665 dependencies 445 dependencies

TA P1 Tn Pn … … Alura TA P3 Mock P1 P2

1,333 dependencies 438 dependencies

TA P1 Tn Pn … … VRaptor TA P3 Mock P1 P2

21,768 dependencies 621 dependencies

TA P1 Tn Pn … … Spring Framework

Sample 2

Validation Manual analysis (2nd author) Manual analysis (1st author)

Data analysis Data collection Manual analysis

TA P1 TA P1 TA P1

Methodology

slide-18
SLIDE 18

TA MockExtractor TA P3 Mock P1 P2

13,547 dependencies 674 dependencies

TA P1 Tn Pn … … Sampling

Commit Comments Commit Comments Commit Comments

132 categories

Commit Comments

7

Categories

Sample 1

P1 Sonarqube TA P3 Mock P1 P2

1,665 dependencies 445 dependencies

TA P1 Tn Pn … … Alura TA P3 Mock P1 P2

1,333 dependencies 438 dependencies

TA P1 Tn Pn … … VRaptor TA P3 Mock P1 P2

21,768 dependencies 621 dependencies

TA P1 Tn Pn … … Spring Framework

Sample 2

Validation Manual analysis (2nd author) Manual analysis (1st author) Discussion

Data analysis Data collection Manual analysis Categorisation

TA P1 TA P1 TA P1

Methodology

slide-19
SLIDE 19

RQ1

RQ1: What test dependencies do developers mock?

slide-20
SLIDE 20

RQ1: What test dependencies do developers mock?

RQ1

0% 25% 50% 75% 100% Database Web service External 
 Dependencies Domain 


  • bject

Java libraries Test support

94% 93% 64% 32% 31% 28%

6% 7% 36% 68% 69% 72%

Mocked Not mocked

slide-21
SLIDE 21

TA MockExtractor TA P3 Mock P1 P2

13,547 dependencies 674 dependencies

TA P1 Tn Pn … … Sampling

Commit Comments Commit Comments Commit Comments

132 categories

Commit Comments

7

Categories

Interview Guideline 3 developers

Sample 1

P1 Sonarqube TA P3 Mock P1 P2

1,665 dependencies 445 dependencies

TA P1 Tn Pn … … Alura TA P3 Mock P1 P2

1,333 dependencies 438 dependencies

TA P1 Tn Pn … … VRaptor TA P3 Mock P1 P2

21,768 dependencies 621 dependencies

TA P1 Tn Pn … … Spring Framework

Sample 2

Validation Manual analysis (2nd author) Manual analysis (1st author) Discussion

Data analysis Interviews & Validation Data collection Manual analysis Categorisation

TA P1 TA P1 TA P1

Methodology

slide-22
SLIDE 22

RQ2

RQ2: Why do developers decide to (not) mock a dependency?

slide-23
SLIDE 23

RQ2

RQ2: Why do developers decide to (not) mock a dependency?

Not when the focus of the test is the integration

Vehicle Car Plane Boat

Mock interfaces rather than a specific implementation Concrete implementation is not easy

slide-24
SLIDE 24

TA MockExtractor TA P3 Mock P1 P2

13,547 dependencies 674 dependencies

TA P1 Tn Pn … … Sampling

Commit Comments Commit Comments Commit Comments

132 categories

Commit Comments

7

Categories

Interview Guideline 3 developers

Commit Comments Review Comment Commit Comments Interview Transcript Commit Comments Commit Comments

Survey (105 respondents)

Sample 1

P1 Sonarqube TA P3 Mock P1 P2

1,665 dependencies 445 dependencies

TA P1 Tn Pn … … Alura TA P3 Mock P1 P2

1,333 dependencies 438 dependencies

TA P1 Tn Pn … … VRaptor TA P3 Mock P1 P2

21,768 dependencies 621 dependencies

TA P1 Tn Pn … … Spring Framework

Sample 2

Validation Manual analysis (2nd author) Manual analysis (1st author) Discussion

Affinity Diagram

Data analysis Interviews & Validation Data collection Manual analysis Categorisation

TA P1 TA P1 TA P1

Methodology

slide-25
SLIDE 25

RQ3

RQ3: Which are the main challenges experienced with testing using mocks?

slide-26
SLIDE 26

RQ3

RQ3: Which are the main challenges experienced with testing using mocks?

Legacy systems Dealing with coupling Production quality code vs mocks

slide-27
SLIDE 27

Discussion

Mockito developer

  • He agreed on all the findings
  • How Mockito can help?
  • What Mockito is supposed to

do more?

Open questions

  • Software quality vs mocks
  • Are slow tests more mocked?
  • How faster are tests with

mocks?

slide-28
SLIDE 28