Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

2017 JavaOne Mutation Testing Session

248 views

Published on

Overview and live demo of mutation testing.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

2017 JavaOne Mutation Testing Session

  1. 1. Intro to Mutation Testing (CON 1694) slideshare.net/boyarsky Twitter @jeanneboyarsky Blog: http://www.selikoff.net Jeanne Boyarsky JavaOne - October 5, 2017
  2. 2. @jeanneboyarsky About Me 15 years as •Java Developer •JUnit user
  3. 3. The Plan 1. About mutation testing 2. Live demo 3. A look at types of mutants 4. Profit??? @jeanneboyarsky
  4. 4. Why write tests? @jeanneboyarsky It used to work!
  5. 5. How know if tests are good? @jeanneboyarsky
  6. 6. If test coverage low @jeanneboyarsky Write more tests! Not ready for mutation testing of class
  7. 7. If test coverage high @jeanneboyarsky All done! Perfect code!
  8. 8. Or is it?Why is it saying nobody is registered? @jeanneboyarsky
  9. 9. Code Review! @jeanneboyarsky
  10. 10. That’s a mutant! @jeanneboyarsky
  11. 11. Too many mutants! They’re everywhere! @jeanneboyarsky
  12. 12. PitClipse to the rescue! @jeanneboyarsky
  13. 13. @jeanneboyarsky PIT Integration Almost
  14. 14. JUnit 5 • Unofficial Fork: https://github.com/tobiasstadler/pitest-junit5-plugin • It’s coming: https://github.com/hcoles/pitest/issues/284 https://github.com/hcoles/pitest/issues/398 @jeanneboyarsky
  15. 15. Easy to run @jeanneboyarsky
  16. 16. The console flies by @jeanneboyarsky
  17. 17. Wait, we just had 100% coverage @jeanneboyarsky
  18. 18. We caught 5 mutants @jeanneboyarsky
  19. 19. More detail @jeanneboyarsky
  20. 20. Level up @jeanneboyarsky
  21. 21. Now 23 survived @jeanneboyarsky
  22. 22. Let’s try it! @jeanneboyarsky
  23. 23. Observations • JUnit tests must pass • Fixing one may take care of more • Found a bug • Better tests @jeanneboyarsky
  24. 24. Now with all mutators @jeanneboyarsky
  25. 25. Observations • Better tests • Unused production code @jeanneboyarsky
  26. 26. Examples of Conditional Mutants @jeanneboyarsky Conditionals Boundary <= vs < Negative Conditionals <= vs > Void Method Call Removes method calls
  27. 27. Examples of Math Mutants @jeanneboyarsky Math * vs / Increments ++ vs -- Invert Negatives x vs -x
  28. 28. Examples of Other Mutants @jeanneboyarsky Return Values x vs x+1 Disabled by default (false positives, duplicates or crashes) Constructor Calls Inline Constants Non Void Method Calls Remove Conditionals Experimental Member Variables Switch
  29. 29. Tips for bigger projects • Watch console to see if still running • Reports on whole project – drill down/split up • Exclude long running tests • Experimental feature: incremental analysis @jeanneboyarsky
  30. 30. Review Code Coverage Mutation Testing Requirements
  31. 31. More info • http://pitest.org/ • https://github.com/philglover/pitclipse • https://dzone.com/articles/introduction-mutation @jeanneboyarsky
  32. 32. @jeanneboyarsky

×