Property-Based Testing with clojure.test.check
Learn to write robust tests that verify properties of your code across a range of inputs using `clojure.test.check`.
Beyond Example Tests
Welcome to Property-Based Testing (PBT)! Traditional unit tests use specific examples to check if your code works. PBT takes a different approach.
Instead of examples, you define properties that your code should always uphold, no matter the input. Then, a PBT tool generates many diverse inputs to try and break those properties.
PBT vs. Example-Based Testing
Think of it this way:
- Example-Based Testing (like
clojure.test): "Does(my-add 2 3)return5?" You pick the inputs. - Property-Based Testing (with
clojure.test.check): "Is(my-add a b)always equal to(my-add b a)for any integersaandb?" The tool generatesaandb.
PBT is excellent at finding edge cases you might not think of manually.
All lessons in this course
- Transducers for Efficient Processing
- Monads & Functional Abstractions
- Property-Based Testing with clojure.test.check
- Lazy Sequences & Infinite Streams