How to use --test option to cargo test

The cargo test command has a --test option that only runs a single "test target". What does "test target" mean? From my attempts to pass a valid argument it clearly isn't a test function. But I'm not really sure what the purpose of this argument is.

Test target is filename (without .rs extension) in tests/ directory.
cargo test --test foo runs tests written in tests/

1 Like

It's for running a single integration test suite (files in test/, or [[test]]s declared in Cargo.toml).

You can filter the test functions in a test suite (including the suite that runs the unit tests defined in your library) by passing a pattern string as a positional argument to the test harness. (Use -- to delimit this from arguments to cargo). All #[test] functions whose qualified path contains the substring will be run.

cargo test -- it_works

cargo test -- some_mod::tests::x
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.