Logo

Developer learning path

Rust

Test Filters in Rust

Test Filters

10

#description

In Rust testing, test filters allow developers to selectively run certain tests instead of running all tests in a test suite. Test filters use the cargo test command with various options to specify which tests should be run.

There are four types of test filters in Rust:

  1. Test Name: developers can run a specific test method by specifying its name using --test <name> option. For example, cargo test --test my_test will run only the my_test function.
  1. Test Module: developers can run all tests in a specific module by specifying its name using --test <module> option. For example, cargo test --test my_module will run all tests in the my_module module.
  1. Test File: developers can run all tests in a specific file by specifying its path using --test <path> option. For example, cargo test --test tests/my_tests.rs will run all tests in the my_tests.rs file.
  1. Test Filter: developers can run tests that match a pattern or a word in their name using --test <filter> option. For example, cargo test --test smoke will run all tests that have the word "smoke" in their name.

Using test filters can save time during development and help developers to focus on specific tests or modules.

March 27, 2023

If you don't quite understand a paragraph in the lecture, just click on it and you can ask questions about it.

If you don't understand the whole question, click on the buttons below to get a new version of the explanation, practical examples, or to critique the question itself.