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

Property-based testing: work harder, not smarter

Property-based testing: work harder, not smarter

Testing is an important part of software development, but how many tests is enough? Should you write a test for every possible value that could be submitted to a function? Property-based testing is a technique that can help you with this conundrum. Instead of writing a specific set of tests, write some generalized tests and let a tool randomly test inputs against your code.

I'll explain in more detail what property-based testing is, how it works, and show some practical examples using Eris, a new PHPUnit extension modeled after Haskell's QuickCheck library.

Joel Clermont

November 07, 2015
Tweet

More Decks by Joel Clermont

Other Decks in Programming

Transcript

  1. What to expect • Why automated testing? • Define property-based

    testing • Anatomy of a test • Examples • Next steps
  2. Automated testing • We already test manually • Developers like

    to save time • Make the computer work for you • Bonus: Code design improves with unit testing
  3. Property-based test • Define a way to generate inputs •

    Run code under test • Make assertions about output • This is the tricky part!
  4. Sample properties • x + 0 = x • x

    * 1 = x • x + y = y + x • strlen(strpad(str, n)) === n
  5. The more things change, the more they stay the same

    http://fsharpforfunandprofit.com/posts/property-based-testing-2/