Doc test
A doc test is an automated test that compiles and runs executable code examples embedded in documentation.
Refactoring to Rust
A documentation test is an automated test generated by compiling and running executable code examples embedded in documentation.
- How it is used
- Validates executable public-API examples while running the ordinary Rust test suite.
- How deep it goes
- Explains Markdown extraction, separate-crate compilation, failure reporting, and implicit-main line-number limitations.
- Examples
- Uses an `add` function with passing, assertion-failing, and type-error examples.
- What you can do after
- Operate Cargo to validate documentation examples and interpret runtime or compilation failures.
Idiomatic Rust
A doc test is an automatically generated test that compiles and executes an executable code example extracted from Rust documentation.
- How it is used
- Uses executable API examples as integration tests while improving library documentation.
- How deep it goes
- Explains automatic discovery, rustdoc preprocessing, generated main, and cargo test execution.
- Examples
- Demonstrates crate-level LinkedList usage, animal appends, and passing generated test output.
- What you can do after
- Apply it via cargo test to verify that documented Rust usage examples compile and execute.
Related concepts
- contractuses · An API contract is a specification of the operations, data, and behavioral expectations that govern interactions between software components.
- doc commentproduced by · A doc comment is a source-code comment associated with a declaration that describes it and can be processed into generated documentation.
- Cargouses · Cargo is Rust’s package manager and build system for managing projects, dependencies, compilation, testing, and related workflows.
- doc exampleproduced by · A doc example is executable code embedded in documentation to illustrate how an API or library is used.
- testkind of · A test is a procedure or check that evaluates behavior using specified inputs or evidence against expected results or criteria.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

