This lesson explains what problem protocols are meant to solve using visual aids. This video lesson is 8 minutes long.
Parts of courses on specific topics
Property-Based Testing can be used at four different times, from design-time to after your users have found a bug, to help you reproduce it.
Testing after an implementation exists and is working is often frowned upon. Your brain is biased toward your implementation, so it’s hard to find good counterexamples. However, in Property-based testing, the system is generating tests, and it doesn’t have a bias.
Although PBT is very valuable for testing after implementing, it still has two challenges. You still need to think of how to trick the tests without having the benefit of modifying the implementation. The second challenge is to avoid duplicating the implementation. A test that uses the same code as the function it tests is useless.
In this lesson we go through the process of testing an existing function. We write many tests, and settle on just a couple that seem to cover the entire functionality.
In this lesson, we implement a function using TDD. Property-based testing is great for doing TDD since the tests are constantly giving you small examples that fail, one at a time. Make it pass, and get another. Make that pass, get another. Eventually, you’ll have the whole thing tested and implemented.
One of the secrets benefits of Property-Based Testing is that it helps you design a system. Think about it: you’ve got a bunch of constraints you know you need to operate within, there are certain desired properties, etc. You can encode those as Property-Based Tests and develop a model (not a real implementation) and see what it would take to meet those requirements. Then, you can use your model to test the real system. In this episode, we design an email sending system that needs a very specific kind of idempotency.
Property-Based Testing lets you search for a sequence of operations that reproduce a bug. Imagine you get a bug report from a user or you find an exception in your logs. You don’t know where it’s coming from, but you know it’s in your database code. How do you find that bug?
PBT lets you do a search over possible sequences of operations. You can design a test to only fail if it finds the same exception. Once you find a failing case, you can turn it into a regular regression test so you don’t need to do the search again.