Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mutation testing 101

Mutation testing 101

OK, so... you write tests to verify that your code is doing what it is expected to do. But who verifies that the tests are "good"? We all know that test coverage means "almost" nothing, so... Who watches the watchmen?

This will be an introduction talk and demo to mutation testing 🙂

Isidro López

June 21, 2019
Tweet

More Decks by Isidro López

Other Decks in Programming

Transcript

  1. “Internal” vs “External” quality The system / component / whatever

    behaves as expected... • https://martinfowler.com/articles/microservice-testing/ • Specification by example / ATDD / BDD • Example mapping • Functional testing • Contract testing • Exploration testing • Performance testing • Penetration testing • etc...
  2. Metrics, metrics everywhere... • Cyclomatic complexity • Duplications • Code

    smells • Maintainability • Technical debt • Test duration • Test coverage: are we covering all the “possible” behaviours of the system? https://sonarcloud.io/dashboard?id=com.islomar.payments%3Apayments-api
  3. “Tell me how you measure me, and I will tell

    you how I will behave” Eliyahu M. Goldratt “You get what you measure”
  4. Simple examples of mutators • Conditional boundaries • Increments •

    Invert negatives • Math • Negation • Return values • Void method calls • Constructor calls • Empty returns • False/True returns • Remove conditionals • etc...
  5. Final considerations • High test coverage means almost NOTHING. Low

    test coverage is a smell... • Mutation testing: only for isolated tests (aka “unit tests”): tests which are fast (FIRST) • Start with the basic mutators • Depending on the complexity and size of the code, it can be very time/resource consuming, watch out!! (combinatorial explosion) ◦ In Pitest you can activate “incremental analysis” (experimental feature)
  6. Resources (I) GOTO 2015: Mutation testing in Python https://www.youtube.com/watch?v=jwB3Nn4hR1o Mutation

    testing in Python with Cosmic Ray https://vimeo.com/171319754 Vicenç García en SCBCN (in Spanish) https://www.youtube.com/watch?v=LWL71b2fc64 Madrid JUG (in Spanish) https://www.youtube.com/watch?v=hk_urzWGqrE