Unit tests live in the same file with #[cfg(test)] mod tests; integration tests go in tests/. Run with cargo test locally—playground simulates assertions with assert!.
assert macros
assert_eq!(add(2, 2), 4);
assert!(score > 0);
Self-check
- Which macro compares equality in tests?
- Where do integration tests live in Cargo projects?
Test organization
Unit tests compile only in test configuration—zero cost in release binaries. Integration tests in tests/*.rs see only the public API, mirroring how external users call your crate.
Use #[should_panic] for expected failures and Result tests with ? inside test functions.