1.2 KiB
1.2 KiB
Randomised Property Testing in Zebra
Zebra uses the proptest crate for randomised property testing.
Most types in zebra-chain have an Arbitrary implementation, which generates randomised test cases.
We try to derive Arbitrary impls whenever possible, so that they automatically update when we make structural changes.
To derive, add the following attribute to the struct or enum:
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
struct Example(u32);
When we want to use those Arbitrary impls in proptests in other crates, we use the proptest-impl feature as a dev dependency:
- in
zebra-chain: make theArbitraryimpl depend on#[cfg(any(test, feature = "proptest-impl"))] - in the other crate: add zebra-chain as a dev dependency:
zebra-chain = { path = "../zebra-chain", features = ["proptest-impl"] }
If we need to add another dependency as part of the proptest-impl feature:
- Add the crate name to the list of crates in the
proptest-implfeaturesentry - Add the crate as an optional
dependenciesentry - Add the crate as a required
dev-dependenciesentry
For an example of these changes, see PR 2070.