Doc test
A doc test is an automated test that extracts, 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.
Also covered in
What to know first
- MarkdownMarkdown is a lightweight markup language that uses readable plain-text syntax to represent structured and formatted documents.
Related concepts
- doc commentuses · A source-code comment intended to document a program element, often associated with a declaration and processable by documentation tools.
- contractuses · A contract is an agreed specification of the conditions, expectations, rights, or obligations that govern behavior or interactions between parties or software components.
- Cargouses · Cargo is Rust’s package manager and build tool for managing projects and dependencies and for building, testing, and running Rust code.
- doc exampleproduced by · A doc example is executable code embedded in documentation to illustrate how an API or library is used.
Questions about doc test
What is doc test?
A doc test is an automated test that extracts, compiles, and runs executable code examples embedded in documentation.
Which Manning books explain doc test?
Refactoring to Rust and Idiomatic Rust.
What should I know before learning doc test?
Manning books that teach doc test usually introduce Markdown first.
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.

