How to run all the test functions under a specific module?

Viewed 868

Say there is a module with multiple tests underneath, such as the following. How do you run all the tests under this module but not other modules?

#[cfg(test)]
mod cool_tests {
   #[test]
   fn first_test() {
      // Test Code
   }

   #[test]
   fn second_test() {
      // Test Code
   }
}
1 Answers

You can simply run all the tests under the module as follows:

cargo test cool_tests::

If you want to filter based on name, say all that start with 'first,' you can run the tests as follows:

cargo test cool_tests::first
Related