#property #quickcheck #shrinking #pbt

monkey_test

A property based testing (PBT) tool like QuickCheck, ScalaCheck and other deriviatives thereof, for the Rust programming language

5 releases (3 breaking)

0.4.0 Feb 10, 2024
0.3.0 Jan 19, 2024
0.2.0 Nov 10, 2023
0.1.1 Sep 26, 2023
0.1.0 Sep 22, 2023

#305 in Testing

Download history 4/week @ 2023-10-29 24/week @ 2023-11-05 6/week @ 2023-11-12 7/week @ 2023-11-19 11/week @ 2023-11-26 10/week @ 2023-12-03 3/week @ 2023-12-10 7/week @ 2023-12-24 3/week @ 2023-12-31 26/week @ 2024-01-14 8/week @ 2024-01-21 9/week @ 2024-01-28 29/week @ 2024-02-04 94/week @ 2024-02-11

143 downloads per month

MIT license

575KB
1.5K SLoC

Monkey Test

monkey test logo

A property based testing (PBT) tool like QuickCheck, ScalaCheck and other deriviatives thereof, for the Rust programming language.

❗This library is in pre-alpha state. Large parts of functionality is missing and API will undergo a lot of change.

Example

#[cfg(test)]
mod tests {
    use monkey_test::*;

    #[test]
    #[should_panic(expected = "Property failed!\nCounterexample: 15")]
    fn test_that_will_fail() {
        monkey_test()
            .with_generator(gen::u8::any())
            .assert_true(|x| x < 15)
    }
}

Getting started

In Cargo.toml, add

[dev-dependencies]
monkey_test = "0"

Then try some small example, like the one above.

Documentation and how-to guide

The Monkey Test documentation (also found on docs.rs) shows how to use the library and tries to be a complete how-to guide to using Monkey Test and property based testing in general. Additional usage examples can be found in the source file tests/basic_usage.rs and other files in test folder.

Current status and missing parts

Currently, in versions 0.x.y, the library is not ready for production use. It is also missing some vital parts, primarly built in generators and shrinkers for:

  • Floating point numbers f32 and f64.
  • Strings.
  • Commonly used data structures besides Vec.
  • Recursive data structures.

Alternative libraries

There are other alternatives for property based testing in Rust. The Monkey Test library exist for mostly subjective reasons, not liking the API experience or the heavy use of macros and attributes in other libraries. Your milage may vary.

The most mature and widely adopted alternatives are Quickcheck and Proptest. Currently, if you want to have a production grade PBT library, choose one of these two. When in doubt, choose Proptest, since it allows for custom generators and shrinkers.

Some other alternatives are checkito and diceprop.

License

Monkey test uses the MIT license.

Dependencies