Testing your code
Rust’s test story is unusually good: cargo test runs unit tests, integration tests and the
examples in your doc comments, and it needs no framework to start.
The articles after the basics are about the tests people skip — the error path, the shared setup, the property you did not think to assert.
Articles
Section titled “Articles”Nothing published in this chapter yet — all 14 articles are still to come.
Coming up (14)
- How to write a unit testthe #[cfg(test)] module
- How to run tests with cargo testfilters, threads, and the output you want
- How to use assert!, assert_eq!, and assert_ne!and the custom message you will want
- How to test that a function panicsshould_panic, and checking the message
- How to write an integration testthe tests/ directory and the library crate
- How to organize tests in a moduleshared helpers without a shared run
- How to share test setup codethe mod common trick
- What is a doctest, and how do you write one?examples in doc comments that cargo test runs
- How to ignore a test with #[ignore]and how to run the ignored ones
- How to run a single test by namefiltering, and –exact when names collide
- How to test private functionsthe child module that can see them
- What is property-based testing?proptest, and the input you would never write
- How to benchmark with criterionwarm-up, outliers, and honest plots
- How to test the error paththe input that should fail, and the message it produces