Property-based testing checks general behavioral rules by running randomized operations against a program instead of requiring a separate unit test for every case. Useful properties include producing no unexpected exceptions and ensuring read-only operations do not modify state. section 1.4
A practical property-based testing workflow includes:
- Generate many random inputs or operation sequences. section 1.4
- Check an expected property or behavioral bound rather than one fixed output. section 1.4
- Replay a failing sequence and remove unnecessary operations to produce a smaller reproducible case. section 1.4
- For comparators, verify the comparator contract with randomized objects; use datasets larger than 31 elements when sorting tests should expose TimSort contract violations. section 7.13
Comparator<Person> PERSON_COMPARATOR =
Comparator.comparing((Person p) -> p.name)
.thenComparing(p -> p.age);
A comparator built from ordered keys provides a concrete target for randomized property checks, especially when testing comparison contracts. section 7.13







