talira

quickcheck (Rust)

Property-based testing for Rust with randomly generated inputs and shrinking

open sourceUnlicense OR MITfree

quickcheck is a Rust crate for property-based testing: given a property function, it randomly generates inputs (integers, floats, tuples, booleans, lists, strings, options and results), calls the property for each, and when one fails shrinks the input to a smaller counter-example, using the same binary-search strategy as QuickCheck for Haskell. The quickcheck_macros crate adds a #[quickcheck] attribute that turns a property into a test. Its README points to Proptest for better shrinking.

Problems it solves

  • test a Rust function against many random inputs
  • find the smallest input that breaks my Rust code
  • write property-based tests in Rust

Features

  • random input generation for common Rust types
  • shrinking of failing inputs to a smaller counter-example
  • quickcheck! macro and #[quickcheck] test attribute
  • discarding inputs outside a property's subset

Limitations

  • Its Arbitrary implementations may change between semver-compatible releases, which can surface new test failures.1

Alternatives

The same job

These do what quickcheck (Rust) does.

  1. Proptest Hypothesis-style property-based testing with shrinking for Rust
  2. Ephyra Rust property-based testing library where a coding agent writes and tunes the generators

Compare quickcheck (Rust) with the top 3