Property-based testing - let your testing library work for you
summary
Shows property-based testing on a concrete discount calculator example (customer join date + birthday → BigDecimal discount) using ScalaCheck and ScalaTest generators, finding a real leap year bug when random dates include Feb 29. Tests run hundreds-to-thousands of generated cases with shrinking to minimal failing examples, explains custom domain generators, the use of assumptions/whenever, flaky-seed recording, and a practical workflow: write example tests first, then add properties for key components.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:55What is property-based testing
- 3:18Example-based testing demo
- 6:50Defining properties for testing
- 9:39History of property-based testing
- 10:44Scala testing libraries
- 13:13Property-based test example
- 15:58How libraries generate data
- 17:02Custom domain generators
- 19:09Using assumptions in tests
- 20:35Challenges of property-based testing
- 21:59Coming up with properties
- 24:26Handling non-determinism
- 25:10Documenting with tests
- 26:14Two testing strategies
- 28:45Benefits and costs
- 30:10Further learning resources
related talks
43mTesting: Property-based testing - let your testing library work(...)
01h 00mA New Approach to Testing with ScalaCheck / Property Based Testing
21mProperty-based testing - let your testing library work for you
46mTesting in the world of Functional Programming
51mProperty Testing: Write Fewer Tests, Find More Bugs
56mProperty based Testing for Functional Domain Models
54mAn Introduction to Property-based Testing
48mDomain Invariants & Property-Based Testing for the Masses
