How to run cargo test for a folder, file, or specific test in RustRover
Question
How to run cargo test scoped to a specific folder, file, or test in RustRover, similar to running tests by scope in VS Code or another editor?
Answer
RustRover offers several ways to invoke cargo test, each scoped to a different unit: folder, file, single test, or a custom cargo command.
Run all tests in a folder or module
Right-click the folder in the Project tool window (the src/ directory or any module folder) and pick Run Tests in 'folder' (the folder name is inserted in single quotes by the IDE). RustRover runs cargo test against everything in that folder. The same gesture works on a file: right-click the file tab or the file in the Project tool window.
Keyboard equivalent: Ctrl+Shift+F10 (Windows/Linux) or Control+R (macOS) when a folder or file is focused in the Project tool window. Both invoke the Run Context Configuration action under the default keymap; on a custom keymap, search the keymap settings for that action name.
Run a single test, a test module, or the whole test file
Each #[test] function and #[cfg(test)] mod block has a gutter icon (a green triangle) next to it in the editor. Clicking the icon runs the corresponding item:
- Next to a
#[test]function: runs that single test. - Next to a
#[cfg(test)] modblock: runs every test in that module. - At the top of a file containing tests: runs every test in the file.
Right-click the gutter icon for Run, Debug, and Run with Coverage variants.
Run in context
Pressing Ctrl+Shift+F10 (Windows/Linux) or Control+R (macOS) with the cursor inside a test function, test module, or test file runs whatever is in the current context. RustRover infers the appropriate cargo test scope from the cursor position.
Custom Cargo run configuration
For test selections that do not fit the above gestures (such as tests filtered by a name prefix, tests behind a feature flag, or tests inside src/ modules where the gutter-and-file gestures are not granular enough), create a custom run configuration:
- Open Run | Edit Configurations.
- Click + and pick Cargo Command.
- Set the command to
test. Add filters or flags in the same field.test foo_testsruns only tests whose name containsfoo_tests;test --features integrationruns tests with theintegrationfeature enabled. - Save the configuration and run it. The configuration is reusable from the run-config dropdown in the toolbar.
Related documentation
- Run tests — the full RustRover guide to running tests, including coverage and the test-output panel.
- Migrate from VS Code to RustRover — a workflow-by-workflow comparison of VS Code and RustRover.
- Building and running — the broader RustRover Build & Run documentation.
Please sign in to leave a comment.