cargo-subunit
A Cargo extension that runs Rust tests and outputs results in subunit v2 format.
Features
- List tests: Display all available tests with unique namespaces
- Run tests: Execute tests and stream results in subunit format
- Load test list: Run specific tests from a file
- Standard cargo test args: Forward any cargo test arguments
Installation
Usage
List all available tests
This outputs test names in their fully-qualified format (e.g., module::submodule::test_name), one per line.
Run all tests with subunit output
The subunit v2 binary output is written to stdout. You can redirect it to a file:
Run specific tests
Pass test filters just like with cargo test:
Run tests from a file
Create a file with test names (one per line):
Pass additional cargo test arguments
Any arguments after -- are forwarded to cargo test:
Integration with testrepository
cargo-subunit integrates seamlessly with testrepository for tracking test history and running tests efficiently.
Create a .testr.conf file in your project root:
[DEFAULT]
test_command=cargo subunit $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
Then you can use testrepository commands:
# Run all tests and record results
# Run only failed tests from the last run
# List test runs
# Show results from the last run
|
How it works
cargo-subunit uses cargo test's unstable JSON output format (enabled via RUSTC_BOOTSTRAP=1) to capture test events, then converts them to subunit v2 format. Each test generates:
- An
inprogressevent when the test starts - A
success,fail,skip, orfail(timeout) event when complete - For failures, stdout/stderr are attached as file content
Requirements
- Rust 2021 edition or later
- The
subunitcrate for protocol serialization
License
Apache-2.0