In rust
running cargo test
runs all (unit, doc, integration, etc) test. Or you can run specific test using filters (2). I don't see a way to run specific groups of test unless all test are in one file.
For example with node.js
and mocha
you can run test in groups. If I only want to run end-to-end test, I setup a custom mocha-config-e2e.js
file and set test directory like spec: 'src/**/test-e2e/*.test.js'
. Then do something like "test-e2e": "NODE_ENV=test mocha --config ./mocha-config-test-e2e.js"
in package.json
. Now when i want to run all end-to-end test, I can run npm run test-e2e
from the terminal. I can repeat this for any group I create.
How do I do the same thing in rust
? How do I run groups of test by directory or regular expression?
Basically I'm looking to run cargo test-e2e
or cargo test-e2e-feature_group1
or something similar where a command runs all test specified by directory or regular expression. This reference shows how to make test in sub-directories run but doesn't reveal how to run specific groups of test.
├── src
├── tests
│ ├── e2e
│ │ ├── feature_group1
│ │ │ ├── example1.rs
│ │ │ ├── example2.rs
│ │ │ ├── example3.rs
│ │ ├── feature_group2
│ │ │ ├── example1.rs
│ │ │ ├── example2.rs
│ │ │ ├── example3.rs
│ ├── integration
│ │ ├── example1.rs
│ │ ├── example1.rs
│ ├── e2e_feature_group1.rs
├── Cargo.toml
The closest I have been able to get is with something like this in tests/e2e_feature_group1.rs
:
#[path = "e2e/feature_group1/example1.rs"]
mod example1;
#[path = "e2e/feature_group1/example2.rs"]
mod example2;
...
Then running cargo test --test e2e
for all test in tests/e2e/feature_group1
that I add to the e2e_feature_group1.rs
file. But that requires creating a tests/[group_name].rs
for every group and listing every test that is in the directory instead of using an expression to catch all test in a directory.
Instead it would be nice to call cargo test --regex "tests/e2e/feature_group1/*"
or cargo test --config "test_config_e2e1.rs"
and put the regex #[path_regex = "e2e/feature_group1/*"]
and any other test config I want to run in that file.