How to run a specific unit test in Rust

#1

I have unit tests in a cargo named school-info and there is a test method called repeat_students_should_not_get_full_marks() .

I can run all tests in the module by cargo test --package school_info .

How may I only run the test repeat_students_should_not_get_full_marks other than running all the tests? I could not find a command in Rust documentation to do it .What will be the command?

#2

cargo test name_of_test

From the cargo test --help:

USAGE:
    cargo test [OPTIONS] [TESTNAME] [-- <args>...]
#3

@baumanj Negative it will run all the tests which similar to that name

#4

<TESTNAME> If specified, only run tests containing this string in their names

If you need to run only that one, I think you need to make the test name unique.

#5

It clearly says If specified, only run tests containing this string in their names so this wont work . I tried out this

#6

You can use the --exact argument. For example:

cargo test -- --exact mymodule::mytest
3 Likes
#7
#8

Yep thats me asking there