Add the rstest crate and use the #[rstest] macro with #[case] arguments to run parameterized tests efficiently.
Use the rstest crate by adding it as a dev dependency and applying the #[rstest] macro to your test function with parameters defined as arguments.
use rstest::rstest;
#[rstest]
#[case(1, 2, 3)]
#[case(4, 5, 9)]
fn test_add(#[case] a: i32, #[case] b: i32, #[case] expected: i32) {
assert_eq!(a + b, expected);
}
Test fixtures with the rstest crate let you run the same test multiple times with different data without rewriting the test code. It works like a spreadsheet where each row is a test case, ensuring your logic holds for various inputs. You use it when you need to verify a function against a list of specific scenarios.