Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

2017 JavaOne Mutation Testing Session

Plus De Contenu Connexe

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

Notes de l'éditeur

  • https://cdn.pixabay.com/photo/2012/05/07/05/18/bug-48020_1280.png
    https://pixabay.com/p-303966/?no_redirect
  • https://cdn.pixabay.com/photo/2012/05/07/05/18/bug-48020_1280.png
    https://pixabay.com/p-303966/?no_redirect
  • http://www.eclemma.org/jacoco/trunk/coverage/
  • https://pixabay.com/p-149251/?no_redirect
  • https://pixabay.com/p-1300226/?no_redirect
  • http://www.publicdomainpictures.net/pictures/180000/velka/mutant-female-41.jpg
  • http://orig01.deviantart.net/920f/f/2015/013/a/8/teenage_mutant_ninja_turtles__2003__drawing__by_n0rvv3g14n_g1rl-d8drynd.jpg
  • Image sources:
    https://commons.wikimedia.org/wiki/File:Antu_netbeans-ide.svg
    https://commons.wikimedia.org/wiki/File:Eclipse-SVG.svg
    https://commons.wikimedia.org/wiki/File:IntelliJ_IDEA_Logo.svg
    https://ant.apache.org
    https://maven.apache.org
    http://junit.org/junit4/
  • Run initially
    Add 2 assertTrue and one assertFalse on tooManyAttendees – incorrectly to show failure with failing unit tests. Wait there’s a bug.
    Fix assertions and see down to three mutants
    In cancel test assertFalse on my registration now down to two mutants
    Then add assertTrue on Barry’s registration and see all mutants killed
  • Change to all mutators
    Run initially and note that down from 23 to 7 – our tests are better
    Note that the wait list logic still isn’t tested enough. Add test for jeanne and maurice cancelling with barry and sai on wait list with four asserts
    4 mutants left
    Add test for sai not on wait list so wait list empty
    2 mutants left
    These two are interesting as they point to unused code – isRoomForMoreAttendees always true and don’t use company name (attendee map value)
  • https://commons.wikimedia.org/wiki/File:Online_Survey_Icon_or_logo.svg

×