Workshop materials and experiments for property based testing tutorial at the Joy of Coding 2015.
The tutorial comes in two flavours:
See Changelog
There are several options available for doing this tutorial:
Clone this repository
git clone https://github.com/qwaneu/property-based-tutorial.git
The Javascript tutorial uses the jsverify library, one of the available Javascript property based testing libraries.
Provided you have Node and NPM installed:
cd exercises/js
npm install jsverify
npm install underscore
cd exercises/hsmoney
stack build
Run the tests with
stack build joy && stack exec joy
Or use the repl, see the detailed README for instructions.
Cloud9 provides a development environment in the cloud: https://c9.io/
You can sign up; it provides a development environment including editors, a terminal, NodeJS and Git support.
Sign in / Log in, open a terminal, and clone this repository:
git clone https://github.com/qwaneu/property-based-tutorial.git
Install the required Node modules:
cd property-based-tutorial/exercises/js
npm install jsverify
npm install underscore
In practice we usually do example based testing. We write an example of how a function or system under test behaves. Examples can communicate very well. It might be difficult to catch all corner cases. And with example based test, we try to find a minimal set of examples, to keep the maintenance burden low.
Example based testing provides just a few data points to capture the system under test. How do you know that you've actually caught those pesky corner cases in your examples?
Property based testing takes a different approach:
In our experience, property based testing can be beneficial in several cases:
Furthermore, Property Based Testing drives your design, something it has in common with Test Driven Development (although it drives your design in a different way). Property based testing forces you to think about invariant properties of your code and capture these explicitly. Defining custom generators helps you get a better understanding of the preconditions of your code.
Property based testing is a relatively new practice. We are still learning about its applicability and usefulness.
Properties: invariants of the code under test; invariants should always be true under all valid inputs
Arbitraries & generators: A generator is a function that can generate arbitrary data of a specific type. An arbitrary combines a generator with a shrinking function.
Shrinking: Shrinking is used when a counter example is found, to reduce the counter example to the smallest one that still fails the property
Property based testing is available for most programming languages, like:
Content type
Image
Digest
sha256:9c474eb7e…
Size
760.3 MB
Last updated
almost 11 years ago
docker pull mostalive/joyofproperties2015