Stateful code is hard to test. Each test defines a sequence of operations on the state, and then you check if it's in the right state at the end. It takes a lot of time to write those, so we don't tend to write a lot of them. And we rarely test the corner cases.
Property-Based Testing (PBT) gets the computer to generate those tests for us. It can generate thousands of tests, each with a different sequence of operations. The fact is that PBT finds bugs in databases, queues, and other stateful systems.
test.check is the Clojure library that implements Property-Based Testing. test.check is deeply integrated into Clojure Spec.
In this course, we build off what we learned in the Beginner's course to take our tests even further. We learn:
- How to build sophisticated generators for your complex, structured data
- A powerful strategy for writing properties when the input is hard to generate
- The inner-workings of generator size and the shrinkage process
- How to test stateful systems—code with mutable state
- To integrate with Spec when Spec's automatic generators aren't good enough
- How to use Spec's fspec and when you have to use test.check directly
Property-Based Testing is a powerful way to test your software. This course starts where the Beginning course left off. We look at more complex generators, interesting strategies for properties, and integration with Clojure Spec.