Use the #[should_panic] attribute with an expected message string to verify that a function panics correctly.
Add the #[should_panic] attribute to your test function to verify that a specific code path panics.
#[test]
#[should_panic(expected = "less than or equal to 100")]
fn greater_than_100() {
Guess::new(200);
}
The expected argument ensures the test only passes if the panic message contains the specified substring.
The #[should_panic] attribute lets you write tests that confirm your code crashes in the right way. Instead of just checking for a correct result, you verify that invalid inputs cause a specific error message. It's like checking that a safety alarm goes off when you break a specific rule.