$30 off During Our Annual Pro Sale. View Details »

Property-based testing 101

Property-based testing 101

Introduction to property-based testing concepts.

Isidro López

August 23, 2017

More Decks by Isidro López

Other Decks in Programming


  1. Property-based testing 101

    View Slide

  2. El problema
    TDD: hacer lo mínimo para que pase vs Generalización vs Edge cases

    View Slide

  3. Definición (I)
    Property-based tests make statements about the output of your code based on the
    input, and these statements are verified for many different possible inputs.
    Rather than writing a test that tests just a single scenario, you write tests that describe
    a range of scenarios and then let the computer explore the possibilities for you rather
    than having to hand-write every one yourself.

    View Slide

  4. A single test is run hundreds of times with randomly generated inputs (fuzzing).
    A property-based testing framework runs the same test over and over with generated
    Definición (II)

    View Slide

  5. View Slide

  6. Example-based testing
    Property-based tests are best combined with example-based tests.
    Examples help you start organizing your thoughts, and they're easier for future-you to
    read and understand when you come back to this code later.
    Humans think in examples. Programs don't extrapolate. Property-based thinking and
    property-based testing can bridge between us and the computer.
    Math, it's a tool.

    View Slide

  7. El origen
    Haskell Quickcheck: http://hackage.haskell.org/package/QuickCheck
    The programmer provides a specification of the program, in the form of properties
    which functions should satisfy, and QuickCheck then tests that the properties hold in a
    large number of randomly generated cases.

    View Slide

  8. Property-based testing en Python
    https://github.com/npryce/python-factcheck >> https://pypi.python.org/pypi/factcheck

    View Slide

  9. https://github.com/islomar/poc-python/tree/master/property-based-testing

    View Slide

  10. Links de interés
    ● http://blog.jessitron.com/2013/04/property-based-testing-what-is-it.html
    ● https://fsharpforfunandprofit.com/posts/property-based-testing/
    ● https://fsharpforfunandprofit.com/posts/property-based-testing-2/

    Property-based testing tools:


    TDD + QuickCheck:


    View Slide

  11. View Slide

  12. View Slide