Skip to content

Glossary: Rust Beyond the Basics

#[test]

Also written: test, tests, #[cfg(test)], should_panic

An attribute marking a function as a test that fails if it panics. `#[cfg(test)]` compiles a module only when testing, and `#[should_panic]` makes a test pass only if the code panics.

Where the book teaches it

Related terms

unit testcargo testassert!, assert_eq!, assert_ne!