[−][src]Attribute Macro rstest::rstest
#[rstest]
Write a test that can be injected with [fixture]
s. You can declare all used fixtures
by passing them as a function's arguments.
use rstest::*; #[fixture] fn injected() -> i32 { 42 } #[rstest] fn the_test(injected: i32) { assert_eq!(42, injected) }
[rstest]
macro will desugar it to something that is not so far from
#[test] fn the_test() { let injected=injected(); assert_eq!(42, injected) }
You can dump all input arguments of your test by using the trace
parameter for the [rstest]
attribute.
use rstest::*; #[fixture] fn injected() -> i32 { 42 } #[rstest(::trace)] fn the_test(injected: i32) { assert_eq!(42, injected) }
Will print an output like
Testing started at 14.12 ...
------------ TEST ARGUMENTS ------------
injected = 42
-------------- TEST START --------------
Expected :42
Actual :43
If you want to trace input arguments but skip some of them that do not implement the Debug
trait, you can also use the notrace(list_of_inputs)
attribute:
#[rstest(::trace::notrace(xzy, have_no_sense))] fn the_test(injected: i32, xyz: Xyz, have_no_sense: NoSense) { assert_eq!(42, injected) }