The examples you provide in documentation can be turned into tests and included in test runs. The practice is referred to as documentation testing. It helps keep documentation up to date with your code. You can find out more about doctests in the rustdoc book.
RustRover automatically detects doctests. You can run them using the methods described below.
Moreover, since doctests are classified as tests, they are included in test runs. For ways to launch tests, refer to the Run tests page.
Run a doctest
To run a specific test, click in the gutter next to the doctest entry:
To run all doctests in the module/project, open the Cargo Run Anything popup (press Control twice) and specify the
cargo test --doccommand with additional arguments if required.
When you run doctests using one of the methods listed above, the IDE automatically creates a configuration and saves it for future use. To modify the current configuration, click the three dots icon, select Modify Run Configuration, and make the adjustments in the Edit Run Configuration dialog.
You can also create a doctest configuration manually: follow the steps for creating a test configuration and specify the
cargo test --doc command with additional arguments if required.
Viewing doctest results
Doctest results appear in the Test runner tab of the Run tool window, together with the results of regular tests. Learn more about manipulating test results on the Explore test results page.