#test #case #tests #unit #testing

macro dev test-case-macros

Provides #[test_case(…)] procedural macro attribute for generating parametrized test cases easily

2 stable releases

2.2.1 Jul 21, 2022
2.1.0 May 18, 2022

#67 in Testing

Download history 1351/week @ 2022-05-14 3531/week @ 2022-05-21 3544/week @ 2022-05-28 4671/week @ 2022-06-04 5700/week @ 2022-06-11 5772/week @ 2022-06-18 7586/week @ 2022-06-25 6710/week @ 2022-07-02 8016/week @ 2022-07-09 9129/week @ 2022-07-16 9079/week @ 2022-07-23 11298/week @ 2022-07-30 10240/week @ 2022-08-06

41,343 downloads per month
Used in 68 crates (via test-case)

MIT license

48KB
1K SLoC

Crates.io Crates.io 1.49+ Docs.rs MIT License Build Status Maintenance

Test Case

Overview

test_case crate provides procedural macro attribute that generates parametrized test instances.

Getting Started

Crate has to be added as a dependency to Cargo.toml:

[dev-dependencies]
test-case = "2.2.1"

and imported to the scope of a block where it's being called (since attribute name collides with rust's built-in custom_test_frameworks) via:

use test_case::test_case;

Example usage:

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

    #[test_case(-2, -4 ; "when both operands are negative")]
    #[test_case(2,  4  ; "when both operands are positive")]
    #[test_case(4,  2  ; "when operands are swapped")]
    fn multiplication_tests(x: i8, y: i8) {
        let actual = (x * y).abs();

        assert_eq!(8, actual)
    }
}

Output from cargo test for this example:

$ cargo test

running 4 tests
test tests::multiplication_tests::when_both_operands_are_negative ... ok
test tests::multiplication_tests::when_both_operands_are_positive ... ok
test tests::multiplication_tests::when_operands_are_swapped ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Documentation

Most up to date documentation is available in our wiki.

License

Licensed under of MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

Contributing

Project roadmap is available at link. All contributions are welcome.

Recommended tools:

  • cargo readme - to regenerate README.md based on template and lib.rs comments
  • cargo insta - to review test snapshots
  • cargo edit - to add/remove dependencies
  • cargo fmt - to format code
  • cargo clippy - for all insights and tips
  • cargo fix - for fixing warnings

Dependencies

~260–670KB
~16K SLoC