Build fluency in the vocabulary of testing a general rule against many randomly generated inputs.
0 / 5 completed
1 / 5
At standup, a dev mentions defining a general rule that must always hold, like sorting a list twice producing the same result as sorting it once, and having a testing framework generate many random inputs to try to break that rule. What is this testing approach called?
Property-based testing defines a general rule, or property, that must always hold, like sorting a list twice producing the same result as sorting it once, and has a testing framework generate many random inputs specifically to try to break that rule. Example-based unit testing checks a fixed, hand-picked input and expected output, which only exercises the specific cases a developer thought to write. This randomized-input, invariant-driven approach is what lets property-based testing explore a far wider range of inputs than a developer would ever hand-write.
2 / 5
During a design review, the team wants a failing randomly generated input to be automatically reduced down to the smallest input that still reproduces the same failure, rather than leaving a developer to debug a large, complicated failing case. Which capability supports this?
Automatic shrinking reduces a failing randomly generated input down to the smallest input that still reproduces the same failure, turning a large, hard-to-read failing case into something a developer can actually debug quickly. Reporting only the original, full-sized generated input leaves a developer to manually untangle which part of a complicated case actually triggered the failure. This shrinking capability is what makes property-based testing's random inputs practical to actually debug once one of them fails.
3 / 5
In a code review, a dev notices a property test asserting that sorting a list twice always produces the exact same result as sorting it once, verified across a large number of randomly generated lists rather than one specific example list. What does this represent?
An idempotence property, verified across many randomly generated inputs, checks that sorting a list twice always produces the exact same result as sorting it once, regardless of what specific list the framework happens to generate. A single hand-picked example list checked once only verifies that particular case, saying nothing about a list the developer didn't think to test. This property, checked across a wide range of generated inputs, gives far broader confidence than any single fixed example could.
4 / 5
An incident report shows a bug triggered by an empty list input reached production undetected, because every example-based test the team had written happened to use a non-empty list, and nobody had thought to add that specific edge case by hand. What practice would prevent this?
Adding property-based tests whose random input generation naturally includes an edge case like an empty list catches exactly the kind of bug that slipped past hand-picked example-based tests in this incident, without requiring a developer to have thought of that specific case explicitly. Continuing to rely solely on example-based tests leaves the test suite dependent on a developer's own imagination for which edge case to cover. This broader, randomized coverage is a key reason property-based testing complements, rather than replaces, example-based testing.
5 / 5
During a PR review, a teammate asks why the team adds property-based tests instead of relying only on hand-picked example-based unit tests that already pass. What is the reasoning?
Example-based tests only cover the specific inputs a developer thought to write, which inherently limits their coverage to whatever edge cases occurred to that developer at the time. Property-based testing generates a much wider range of inputs, including an edge case a developer might never have considered, like an empty collection or an extreme numeric value. The tradeoff is that a property-based test requires the added upfront work of defining a genuinely general, always-true property, which isn't always as straightforward to articulate as a single concrete example.