Testing basics
Tests are a first-class part of the language, not a library you add. A function marked `#[test]` is compiled only for `cargo test` and is invisible to release builds.
The convention is a `mod tests` block at the bottom of the same file, marked `#[cfg(test)]`, with `use super::*;` to pull in what it is testing. Integration tests that use only the public API live in a top-level `tests/` directory.
`assert_eq!` prints both values when it fails, `assert!` checks a condition, and `#[should_panic]` asserts that something correctly refuses to continue.
Run it and change it
The editor below is live: edit anything and the real compiler output updates by itself.
Contrast AAA · 16.6:1
15px