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

Property-based testing for the masses

jub0bs
February 28, 2017

Property-based testing for the masses

Talk given at corkdev.io.

(See https://www.meetup.com/corkdev-io/events/237848006/)

jub0bs

February 28, 2017
Tweet

More Decks by jub0bs

Other Decks in Programming

Transcript

  1. Gluttony • too many test cases for the same behaviour

    • bloated test suite • tedious to write, read, maintain
  2. Sloth • Test cases are too few. • Tests lack

    imagination, miss edge cases.
  3. Wrath • Scenarios cannot lay claim to completeness. • Leaves

    reader to infer actual general behaviour from tests
  4. Envy • The size of the test suite is fixed.

    • A bigger test suite requires writing more test cases.
  5. We want to make sure the tests pull their weight

    by making them expressive, so that we can tell what's important when we read them and when they fail, and by making sure they don’t become a maintenance drag themselves. Nat Pryce & Steve Freeman (GOOS book, p227)
  6. Lust • reuse of test data • coupling between test

    cases • hurts evolvability • generators provide test data
  7. Gluttony • too many test cases for the same behaviour

    • bloated test suite • tedious to write, read, maintain • one behaviour = one property
  8. Greed • Slave to code-coverage metrics • "For all input

    values allowed by the compiler, does the implementation fulfill the API’s contract?”
  9. Sloth • Test cases are too few. • Tests lack

    imagination, miss edge cases. • Leave the tedium to the library. • More readable tests.
  10. Wrath • Scenarios cannot lay claim to completeness. • Leaves

    reader to infer actual general behaviour from tests • Higher level of abstraction, no ambiguity
  11. Envy • The size of the test suite is fixed.

    • A bigger test suite requires writing more test cases. • The size of the test suite can be tuned.
  12. Pride • Frivolous, noisy data • Fun, but distracting… •

    High power-to-weight ratio • The truth, all the truth, nothing but the truth.
  13. The whole point is that [production code and testing code]

    double-check on each other. You have a problem when something goes red because they are mismatched. The basic, fundamental thing is that it’s a double-check mechanism. Martin Fowler (https://www.youtube.com/watch? v=dGtasFJnUxI&t=23m)
  14. In conclusion, property-based tests… • raise the level of abstraction

    • increase your confidence in the system under test • reduce the maintenance burden of your tests • allow you to spend more time on other valuable activities Questions?