<skill_overview> Write fast, reliable, and maintainable Rust tests
Writing unit tests Adding integration tests Testing async code Improving test reliability
The Rust Book - Testing
</skill_overview> <test_structure>
Use #[cfg(test)] mod tests in the same module for unit tests Put integration tests in tests/ as separate crates Keep tests independent and deterministic
</test_structure> <arrange_act_assert> Structure each test with Arrange, Act, Assert
#[test] fn add_two_numbers_returns_sum() { let result = add(2, 3); assert_eq!(5, result); }
</arrange_act_assert> <async_tests>
Use an async test harness provided by your runtime Avoid sleeps; use timeouts and deterministic inputs
</async_tests>
Use assert!, assert_eq!, assert_ne! for clarity Use matches! for enum pattern assertions
<anti_patterns> Tests that depend on execution order Hitting real external services in unit tests Global mutable state shared across tests </anti_patterns>