Skip to content

Instantly share code, notes, and snippets.

@JohnScience
Created August 7, 2024 23:04
Show Gist options
  • Save JohnScience/916611a705fae5a181eb04b678cdc634 to your computer and use it in GitHub Desktop.
Save JohnScience/916611a705fae5a181eb04b678cdc634 to your computer and use it in GitHub Desktop.

Examples of using cargo test

cargo test - run all tests, which are not ignored. Their stdout is not shown/printed.

cargo test --help - see the documentation of cargo test. Note that it does not display the test options.

cargo test top_level_mod::tests::test_fn_name -- --exact - run a single test 1. The --exact argument ensures that similar test names won't be executed 2. Note that the path does not include the crate name.

Also see

Footnotes

  1. If you use VS Code, you can see the module path by hovering over the function definition.

  2. Surprisingly, I didn't find where to find information about the --exact flag. However, I found the usage example thanks to this Stack Overflow answer. And it seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment