Skip to content

moolight-seashell/vscode-rust-test-adapter-fork

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

322 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rust VS Code Test Explorer

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.

Install

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.

Current Features

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.

Roadmap

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

Other Projects

Here's some of our other Rust-related projects you may want to check out!

License

MIT - see license details here

Features

  • πŸ” 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

New in v0.11.4 Integration tests

This version adds support for integration tests

New in v0.11.3: Navigate to Test Functionality

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

How It Works

The extension now:

  1. Analyzes your project structure during test discovery
  2. 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
  3. When you click a test, it opens the file and navigates to the test location
  4. If the primary location is not found, it performs a workspace-wide search for the test function

Installation

Install from the Visual Studio Code Marketplace or by searching for "Rust Test Explorer" in the VS Code Extensions view.

Prerequisites

Usage

  1. Open a Rust project in VS Code
  2. Open the Test Explorer by clicking the test icon in the Activity Bar
  3. The extension will automatically discover your tests
  4. Click the run button next to any test or test suite to execute it
  5. Click any test name to navigate to its source code πŸ“

Configuration

The extension supports the following configuration options:

{
    "rustTestExplorer.rootCargoManifestFilePath": "path/to/Cargo.toml",
    "rustTestExplorer.logpanel": true
}

Settings

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

Project Structure Support

The extension works with various Rust project structures:

Single Package

my-project/
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.rs
β”‚   └── main.rs
└── tests/
    └── integration_test.rs

Workspace

workspace/
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ package1/
β”‚   β”œβ”€β”€ Cargo.toml
β”‚   └── src/lib.rs
└── package2/
    β”œβ”€β”€ Cargo.toml
    └── src/main.rs

Binary Project with Multiple Targets

my-project/
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs
β”‚   └── bin/
β”‚       β”œβ”€β”€ tool1.rs
β”‚       └── tool2.rs
└── tests/
    └── integration_test.rs

Test Types Supported

  • Unit Tests: Tests within your source code modules
  • Integration Tests: Tests in the tests/ directory
  • Documentation Tests: Tests within documentation comments

Debugging and Logging

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.

Troubleshooting

Tests Not Discovered

  1. Ensure your project has a valid Cargo.toml file
  2. Check that your tests are properly annotated with #[test]
  3. Enable logging to see detailed discovery information

Go to Test Not Working

  1. Check the output logs for navigation details
  2. Ensure the test files exist and are accessible
  3. The extension will fall back to workspace search if direct navigation fails

Performance Issues

  1. Large workspaces may take time to discover all tests
  2. Consider using workspace exclusions if needed
  3. Enable logging to identify bottlenecks

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Known Issues

  • Documentation test navigation may not be as precise as unit/integration tests
  • Very large workspaces may experience slower test discovery

About

Rust Test Explorer extension for VS Code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 99.7%
  • JavaScript 0.3%