Reputation: 560
Is there a way to only run integration tests, but not unit-tests?
I've tried:
cargo test --tests
: runs unit + integration tests
cargo test --test test_name
: runs one specified test
Is it currently not possible to only run integration tests or am I missing something?
Upvotes: 25
Views: 7312
Reputation: 818
I would like to supplement answer.
If you need to run only ONE integration test method (e.g. 'integration_test_method') you can do that by following command:
cargo test --test integration_tests 'integration_test_method'
RUST_LOG=DEBUG RUST_BACKTRACE=full cargo test --test integration_tests 'integration_test_method' -- --exact --show-output --nocapture
Upvotes: 4
Reputation: 2012
You can run ONLY the integration tests by:
cargo test --test '*'
Please note that only '*'
will work; neither *
nor "*"
works.
Reference: https://github.com/rust-lang/cargo/issues/8396
Upvotes: 42
Reputation: 1374
Thing is, Cargo doesn't really distinguish between integration tests and unit tests, since there isn't a real difference between the two in terms of how you manage and implement them; the difference is purely semantic. Not all codebases even have that separation. The book and the reference call them unit tests and integration tests for simplicity and to avoid confusion, but technically there is no such distinction.
Instead of separating tests into two logical categories, Cargo has a flexible filtering system, which allows you to only run tests when their name matches a certain pattern. The book has a section dedicated to this system. If you'd like to filter out certain tests because they took a long time to run or are otherwise undesirable to be run along with all others, annotate a test with #[ignore]
. Otherwise, use a certain naming methodology for the tests so that you can filter them out by their name.
The Cargo reference page also mentions the fact that you can use the target options in the Cargo.toml
manifest to control what is run when you use --tests
.
Upvotes: 0