Property-based testing checks stated properties of code across generated inputs instead of comparing one known input with one expected result. A library generates randomly distributed inputs, increasing their complexity, to test whether the properties continue to hold. section 14.5.2
A conventional test might call flipCase with Hello and check one result. A property-based test describes the relationship that flipCase must preserve for any input, allowing the test library to explore strings of different lengths and characters. section 14.5.2
Use property-based tests when:
- The possible inputs are so large or varied that hand-written cases cannot provide enough confidence. section 14.5.2
- Several properties together describe the required behavior more effectively than individual expected outputs. section 14.5.2
- You can invest more writing effort for tests that examine many generated inputs rather than one or two selected examples. section 14.5.2
Testing flipCase
Instead of asserting a result for the single input Hello, state rules governing the relationship between each input string and the output of flipCase. FsCheck then starts with simple strings, such as a single letter, and progressively tries more complex strings. section 14.5.2
Figure 14.3 Testing a function by proving that for any given input, it exhibits a set of rules or properties that govern the relationship between the input and output
Compare an explicit expected-output test with a test that proves rules governing the relationship between input and output. section 14.5.2







