rstest
use procedural macro to implement simple fixtures and table
based tests. To use it add follow lines to your Cargo.toml
file:
[dev-dependencies]
rstest = "0.4"
The core idea is that every input arguments of your test function will be resolved by call a function with the same name. Example:
```rust use rstest::rstest;
pub fn fixture() -> u32 { 42 }
fn shouldsuccess(fixture: u32) { asserteq!(fixture, 42); }
fn shouldfail(fixture: u32) { assertne!(fixture, 42); } ```
Moreover you can use rstest_parametrize
macro to implement table
based tests: you must indicate the arguments tha you want use in your cases
and provide them for each case you want to test.
rstest_parametrize
generates an independent test for each case.
```rust
case(0, 0),
case(1, 1),
case(2, 1),
case(3, 2),
case(4, 3)
)] fn fibonaccitest(input: u32, expected: u32) { asserteq!(expected, fibonacci(input)) } ```
Running cargo test
in this case executes five tests:
```bash running 5 tests test fibonaccitest::case1 ... ok test fibonaccitest::case2 ... ok test fibonaccitest::case3 ... ok test fibonaccitest::case4 ... ok test fibonaccitest::case5 ... ok
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ```
You can learn more on Docs and
find more examples in resources
directory and in
rs8080
that use this module intensely.
Licensed under either of
Apache License, Version 2.0, (LICENSE-APACHE or [license-apache-link])
MIT license (LICENSE-MIT or [license-MIT-link]) at your option.