Rust Test Explorer for VS Code that enables viewing and running your Rust tests from the VS Code Sidebar.
This is a fork of the original. This version navigates to the test location if you click on the test.
Download VSIX package and install in VSCode from command pallet: Extensions: Install from VSIX....
Functional, but still in an early Beta/Preview !!!!
Bugs are inevitable π
See the Test Explorer UI Extension for additional information.
Detected unit tests will be viewable and runnable from the Test Explorer window as long as there is a Cargo.toml file in the root of the directory. It should also work with Cargo Workspaces, as well as packages that have both bin and lib targets.
The tree will reflect the package -> target -> module -> ... hierarchical structure. However, the tree will flatten the package level if there's only a single package, and/or at the target level if a package only has a single target containing unit tests.
We've got some sample projects in our samples repo for various scenarios.
The initial focus is the core functionality of viewing and running first unit tests.
Afterwards we're tentatively planning to make the individual test results available in the tree (i.e. when you click on failed test case node in the tree, test output will be viewable in VS Code Output Window). Next, we want to support discovering and running integration tests and documentation tests.
More info can be found in the GitHub Project
Here's some of our other Rust-related projects you may want to check out!
- rusty-hook - A git hook utility for your Rust projects
- VS Code Rust Extension Pack - A minimalist extension pack for Rust development in VS Code
MIT - see license details here
- π Test Discovery: Automatically discovers unit, integration, and documentation tests in your Rust projects
βΆοΈ Test Execution: Run tests individually or in groups directly from the Test Explorer- π Go to Test: Click on any test to navigate directly to its source code (NEW in v0.11.5!)
- π§ Workspace Support: Works with both single packages and Cargo workspaces
- π Test Results: View test results with detailed output and error information
- π Performance: Efficient test discovery and execution using Cargo's native capabilities
- π Enhanced Logging: Comprehensive logging for debugging test discovery and navigation
This version adds support for integration tests
This version introduces the highly requested "go to test" functionality:
- Click to Navigate: Simply click on any test in the Test Explorer to open the corresponding source file
- Smart Location Detection: Automatically infers file locations based on Rust project conventions
- Fallback Search: If the initial file detection fails, the extension will search your workspace for the test function
- Enhanced Logging: Detailed logging helps debug test discovery and navigation issues
The extension now:
- Analyzes your project structure during test discovery
- Maps each test to its likely source file location based on Rust conventions:
- Unit tests β
src/lib.rs,src/main.rs, or corresponding module files - Integration tests β
tests/directory - Binary tests β
src/bin/directory
- Unit tests β
- When you click a test, it opens the file and navigates to the test location
- If the primary location is not found, it performs a workspace-wide search for the test function
Install from the Visual Studio Code Marketplace or by searching for "Rust Test Explorer" in the VS Code Extensions view.
- Test Explorer extension (automatically installed as a dependency)
- Rust toolchain with Cargo
- Open a Rust project in VS Code
- Open the Test Explorer by clicking the test icon in the Activity Bar
- The extension will automatically discover your tests
- Click the run button next to any test or test suite to execute it
- Click any test name to navigate to its source code π
The extension supports the following configuration options:
{
"rustTestExplorer.rootCargoManifestFilePath": "path/to/Cargo.toml",
"rustTestExplorer.logpanel": true
}| Setting | Type | Default | Description |
|---|---|---|---|
rustTestExplorer.rootCargoManifestFilePath |
string | "" |
Path to the root Cargo.toml file for your workspace |
rustTestExplorer.logpanel |
boolean | true |
Enable logging to the VS Code output panel for debugging |
The extension works with various Rust project structures:
my-project/
βββ Cargo.toml
βββ src/
β βββ lib.rs
β βββ main.rs
βββ tests/
βββ integration_test.rs
workspace/
βββ Cargo.toml
βββ package1/
β βββ Cargo.toml
β βββ src/lib.rs
βββ package2/
βββ Cargo.toml
βββ src/main.rs
my-project/
βββ Cargo.toml
βββ src/
β βββ main.rs
β βββ bin/
β βββ tool1.rs
β βββ tool2.rs
βββ tests/
βββ integration_test.rs
- Unit Tests: Tests within your source code modules
- Integration Tests: Tests in the
tests/directory - Documentation Tests: Tests within documentation comments
Enable detailed logging by setting rustTestExplorer.logpanel to true. This will provide comprehensive information about:
- Test discovery process
- File location detection
- Navigation attempts
- Error details
View logs in the "Rust Explorer Log" output channel.
- Ensure your project has a valid
Cargo.tomlfile - Check that your tests are properly annotated with
#[test] - Enable logging to see detailed discovery information
- Check the output logs for navigation details
- Ensure the test files exist and are accessible
- The extension will fall back to workspace search if direct navigation fails
- Large workspaces may take time to discover all tests
- Consider using workspace exclusions if needed
- Enable logging to identify bottlenecks
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Documentation test navigation may not be as precise as unit/integration tests
- Very large workspaces may experience slower test discovery