The #[test_matrix] attribute generates a test for every possible combination (the Cartesian product) of the provided sets of values.
A test matrix consists of:
- Sets of values (Required): Multiple sets of values to combine. The number of sets must match the number of arguments in the test body.
- Expected result (Optional): An expected value applied to every combination generated.
- Test case description (Optional): A prefix applied to the generated test names.
- Test body (Required): The logic applied to every combination.
This is useful for testing how a function behaves across a wide range of input permutations.
#[test_matrix(vec![1, 2], vec!["a", "b"], "desc")]
fn my_matrix_test(val: i32, s: &str) {
// This will run for (1, "a"), (1, "b"), (2, "a"), and (2, "b")
}