Skip to content

3vilM33pl3/vscode-rust-test-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

329 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][test-explorer-extension-url] 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!

  • [rusty-hook][rusty-hook-crate-url] - A git hook utility for your Rust projects
  • [VS Code Rust Extension Pack][vscode-rust-pack-extension-url] - A minimalist extension pack for Rust development in VS Code

License

MIT - see license details [here][license-url]

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
  • πŸ”§ Workspace Support: Works with both single packages and Cargo workspaces
  • πŸ“Š Test Results: View test results with detailed output and error information (NEW in v0.11.6!)
  • πŸš€ 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.6: Test Output Display

This version adds support for displaying detailed test output in the Test Explorer:

  • Detailed Failure Messages: When tests fail, you can now see the complete output including:
    • Assertion failure details with expected vs actual values
    • Panic messages and stack traces
    • File locations and line numbers where failures occurred
    • Any custom output from your tests
  • Improved Cargo Path Detection: The extension now uses the which command to find cargo instead of hardcoded paths
  • Enhanced Error Handling: Better error messages when cargo commands fail

How Test Output Works

When a test fails, the Test Explorer will now show:

  1. The test status (passed/failed/skipped)
  2. For failed tests, the complete error message in the test details panel
  3. All output that would normally appear when running cargo test in the terminal

This makes debugging test failures much easier without having to switch to the terminal!

New in v0.11.5: Navigate to Unit Tests

This version introduced the ability to navigate directly to unit test source code:

  • Click to Navigate: Click on any unit test in the Test Explorer to jump directly to its location in the source code
  • Smart Navigation: The extension automatically determines the correct file location based on Rust's module structure
  • Fallback Search: If the test location cannot be determined from the module path, the extension searches the workspace for the test function
  • Enhanced Test Discovery: Improved test location tracking during the discovery phase

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 adaptor for VSCode Test Explorer. This is a fork of the original. This version navigates to the test location if you click on the test and shows the output of failed tests

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors