#property-testing #properties #quickcheck #testing-tools #hypothesis #shrinking

monkey_test

A property based testing (PBT) tool like QuickCheck, ScalaCheck and similar libraries, for the Rust programming language

9 releases (breaking)

0.7.1 Apr 12, 2024
0.7.0 Apr 12, 2024
0.6.0 Mar 27, 2024
0.5.0 Mar 2, 2024
0.1.1 Sep 26, 2023

#219 in Testing

Download history 2/week @ 2024-01-14 4/week @ 2024-02-04 12/week @ 2024-02-11 7/week @ 2024-02-18 150/week @ 2024-02-25 23/week @ 2024-03-03 65/week @ 2024-03-10 2/week @ 2024-03-17 151/week @ 2024-03-24 22/week @ 2024-03-31 235/week @ 2024-04-07 37/week @ 2024-04-14

445 downloads per month

MIT license

630KB
3K SLoC

Monkey Test

monkey test logo

A property based testing (PBT) tool like QuickCheck, ScalaCheck and similar libraries, for the Rust programming language.

☝️ Note! This library is in active development. Parts of functionality is missing and API can undergo changes. For details on recent changes, see the CHANGELOG.

Example

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

    #[test]
    #[should_panic(expected = "Property failed!\nFailure: 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 in active development. It is currently missing some parts, primarly built in generators and shrinkers for:

  • Strings.
  • Commonly used data structures besides Vec.
  • Recursive data structures.

Other known limitations:

  • For now, integer and float generators do not limit them self to shrink to values within given generator range, but will by default shrink toward zero. For instance, let say that we create generator monkey_test::gen::i64::ranged(10..100), the associated shrinker will not only try candidates withing the given range 10..100, but can also try other values like -10 and will ultimately try to shrink toward zero.

For details on recent changes, see the CHANGELOG.

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.

Contributions

This library needs feedback from users to become even better. Feel free to open a issue or open a pull request.

All work in Monkey Test is licensed under the terms of the MIT license. By submitting a contribution you are agreeing to licence your work under those terms.

Dependencies