Property-Based Testing

Property-based testing involves defining properties that your code should satisfy for a wide range of input values. You describe the general behavior of the program, and the testing framework generates random inputs to check if the properties hold true. Example:

Suppose you have a sorting function. A property you could test is that the output list should have the same length as the input list, and the elements should be in an increasing order.

Consider using:

  • proptest: A powerful crate for property-based testing, where you define properties that your code should satisfy, and proptest generates many random inputs to verify those properties.
  • quickcheck: Another property-based testing crate. proptest is often preferred for its flexibility.

proptest

proptest-website proptest proptest-crates.io proptest-github proptest-lib.rs cat-development-tools::testing

Hypothesis-like property-based testing and shrinking.

[dev-dependencies]
proptest = "1.0.0"
// COMING SOON

Test Data Generation with fake

fake fake-crates.io fake-github fake-lib.rs

An easy to use library and command line for generating fake data like name, number, address, lorem, dates, etc.

Often done with custom functions or data structures, but crates like fake can be useful for generating realistic test data.

// COMING SOON