Want this course?
When to test: before implementation
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.
When to test: after implementation
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.