Tour · 24 of 25
One @derive line gives a type random test inputs, so a property test finds the case you missed
Hand-picked examples test the cases you thought of. A property test states a
rule, here "parsing a printed price gives the price back", and checks it on
many generated values. @derive(Arbitrary, Debug, Eq) writes the three impls
the test needs: random Price values, printing one when it fails, and
comparing two. When the rule breaks, the test fails with the seed that
reproduces it, and hd test also shrinks the failing input to a small one,
such as Price { cents: -1000 }. The derivations are written once, at the
type, not per test.
Test: Ctrl+Enter · Pages: Alt+← Alt+→