[−][src]Module fluid::wiki::theory
A #[theory]
is a test more complex than a fact, that must be proven or inferred with multiple cases.
Therefore, a theory must come with its multiple test case
s, for example:
#[theory] #[case("Cerberus", 3)] #[case("Hydra", 7)] #[case("Janus", 2)] #[case("A regular dice", 6)] #[case("Normal guy", 1)] fn each_creature_has_a_correct_number_of_faces(name: &str, nbr_faces: u8) { number_of_faces(name).should().be_equal_to(nbr_faces); }
If the test fails, it displays a nice error message:
failures:
---- each_creature_has_a_correct_number_of_faces::case_A_regular_dice_6 stdout ---- The test failed at src/main.rs:14, for the case name = "A regular dice", nbr_faces = 6: number_of_faces ( name ) has the value 1. It should be equal to 6 but it is not.
It is possible to use standard assertions inside of the theory
function,
but it makes few sense, because without should()
, there would be no
prettified error message nor case information in case of failed test.