to mock or not to mock
play

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


  1. To Mock Or Not To Mock? An Empirical Study on Mocking Practices Davide Spadini , Mauricio Aniche, 
 Magiel Bruntink, Alberto Bacchelli @DavideSpadini

  2. How do I test this?

  3. With dependencies Without dependencies

  4. Mock Unit under test Unit under test

  5. With dependencies

  6. With dependencies

  7. With dependencies

  8. Without dependencies • Faster • Easier

  9. Without dependencies You lose in reality, after all, it is just a simulation!

  10. So, what should we do? Not to Mock To Mock

  11. Research Questions 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?

  12. Methodology Opensource Industrial

  13. Methodology Sonarqube T A P 1 Alura T A P 1 VRaptor T A P 1 Spring Framework T A P 1

  14. Methodology Sonarqube T A T A P 1 Mock P 3 P 2 P 1 13,547 dependencies Alura T A T A P 1 Mock P 3 P 2 P 1 1,665 dependencies VRaptor T A T A P 1 Mock P 3 P 2 P 1 1,333 dependencies Spring Framework T A T A P 1 Mock P 3 P 2 P 1 21,768 dependencies MockExtractor

  15. Methodology Data collection Sonarqube T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 13,547 dependencies 674 dependencies Alura T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 1,665 dependencies 445 dependencies VRaptor T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 1,333 dependencies 438 dependencies Spring Framework T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 21,768 dependencies 621 dependencies MockExtractor Sampling

  16. Methodology Data collection Data analysis Manual analysis Sonarqube T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 13,547 dependencies 674 dependencies Alura Sample 1 T A Manual analysis T A P 1 (2nd author) T A P 1 … … Mock P 3 P 2 T n P n P 1 1,665 dependencies 445 dependencies Validation VRaptor T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 1,333 dependencies 438 dependencies Sample 2 Spring Framework Manual analysis (1st author) T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 21,768 dependencies 621 dependencies MockExtractor Sampling

  17. Methodology Data collection Data analysis Manual analysis Categorisation Sonarqube T A Discussion T A P 1 T A P 1 … … Commit Commit 132 Commit Mock Comments Comments Comments P 3 P 2 T n P n categories P 1 13,547 dependencies 674 dependencies Alura Sample 1 Commit 7 Comments T A Manual analysis T A P 1 (2nd author) T A P 1 … … Categories Mock P 3 P 2 T n P n P 1 1,665 dependencies 445 dependencies Validation VRaptor T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 1,333 dependencies 438 dependencies Sample 2 Spring Framework Manual analysis (1st author) T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 21,768 dependencies 621 dependencies MockExtractor Sampling

  18. RQ1: What test dependencies do developers mock? RQ1

  19. RQ1: What test dependencies do developers mock? Mocked Not mocked 100% 28% 31% 32% 64% 93% 94% RQ1 75% 72% 69% 68% 50% 36% 25% 7% 6% 0% Database Web service External 
 Domain 
 Java libraries Test support Dependencies object

  20. Methodology Data collection Data analysis Categorisation Sonarqube Manual analysis T A Discussion T A P 1 T A P 1 … … Commit Commit 132 Commit Mock Comments Comments Comments P 3 P 2 T n P n categories P 1 13,547 dependencies 674 dependencies Alura Sample 1 Commit 7 Comments T A Manual analysis T A P 1 (2nd author) T A P 1 … … Categories Mock P 3 P 2 T n P n P 1 Interviews & Validation 1,665 dependencies 445 dependencies Validation VRaptor Interview T A Guideline T A P 1 T A P 1 … … Mock 3 developers P 3 P 2 T n P n P 1 1,333 dependencies 438 dependencies Sample 2 Spring Framework Manual analysis (1st author) T A T A P 1 T A P 1 … … Mock P 3 P 2 T n P n P 1 21,768 dependencies 621 dependencies MockExtractor Sampling

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

  22. RQ2: Why do developers decide to (not) mock a dependency? RQ2 Vehicle Car Plane Boat Not when the Mock interfaces Concrete focus of the rather than a implementation test is the specific is not easy integration implementation

  23. Methodology Data collection Data analysis Sonarqube Manual analysis Categorisation T A Discussion T A P 1 T A P 1 … … Commit Commit 132 Commit Mock Comments Comments Comments P 3 P 2 T n P n categories P 1 13,547 dependencies 674 dependencies Alura Sample 1 Commit 7 Comments T A Manual analysis T A P 1 (2nd author) T A P 1 … … Categories Mock P 3 P 2 T n P n P 1 Interviews & Validation 1,665 dependencies 445 dependencies Validation VRaptor Interview T A Guideline T A P 1 T A P 1 … … Mock 3 developers P 3 P 2 T n P n P 1 Commit Review Commit Comments Interview Comment 1,333 dependencies Comments 438 dependencies Sample 2 Transcript Spring Framework Manual analysis (1st author) T A Commit Commit T A P 1 Comments T A P 1 Comments … … Mock P 3 P 2 T n P n P 1 Survey 21,768 dependencies 621 dependencies Affinity Diagram (105 respondents) MockExtractor Sampling

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

  25. RQ3: Which are the main challenges experienced with testing using mocks? RQ3 Production quality Dealing with Legacy systems code vs coupling mocks

  26. Discussion Open questions Mockito developer • Software quality vs mocks • He agreed on all the findings • Are slow tests more mocked? • How Mockito can help? • How faster are tests with • What Mockito is supposed to mocks? do more?

Recommend


More recommend