| Crates.io | cargo-test-filter |
| lib.rs | cargo-test-filter |
| version | 0.1.1 |
| created_at | 2025-12-22 05:10:23.971898+00 |
| updated_at | 2025-12-22 08:33:31.171408+00 |
| description | A cargo subcommand for intelligent test filtering and compilation |
| homepage | https://github.com/johnproblems/cargo-test-filter |
| repository | https://github.com/johnproblems/cargo-test-filter |
| max_upload_size | |
| id | 1999084 |
| size | 74,291 |
A cargo subcommand for intelligent test filtering. Run only the tests you need—by tag, type, or pattern.
Cargo's built-in test filtering has limitations:
cargo test runs both unit and integration tests togetherGitHub issues #8396 and #8282 document these pain points.
cargo-test-filter provides function-level test filtering with:
cargo install cargo-test-filter
Or build from source:
git clone https://github.com/johnproblems/cargo-test-filter
cd cargo-test-filter
cargo install --path .
Use comment-based tags (no proc macros required):
// @tag: fast
// @tag: api
#[test]
fn test_api_endpoint() {
// ...
}
// @tag: slow
// @tag: database
#[test]
fn test_database_migration() {
// ...
}
Or use attribute syntax:
#[test_tag("fast")]
#[test]
fn test_quick_calculation() {
// ...
}
# Run only tests tagged "fast"
cargo test-filter --tag fast
# Run only integration tests
cargo test-filter --integration
# Run unit tests excluding slow ones
cargo test-filter --unit --exclude-tag slow
# List all tests with their tags
cargo test-filter --list
# Filter by test name pattern
cargo test-filter --name api
# Combine filters
cargo test-filter --integration --tag database
--integration: Run only integration tests (tests in tests/ directory)--unit: Run only unit tests (tests in src/ files)--tag <TAG>: Filter by tag (comma-separated for multiple: --tag fast,api)--exclude-tag <TAG>: Exclude tests with these tags--name <PATTERN>: Filter tests by name pattern--path <PATTERN>: Filter tests by file path pattern--list: List matching tests without running them-v, --verbose: Show detailed output including discovered tests and timingTwo formats are supported:
// Comment-based (recommended - no dependencies needed)
// @tag: fast
#[test]
fn my_test() {}
// Attribute-based
#[test_tag("fast")]
#[test]
fn my_test() {}
Tags must appear immediately before the #[test] attribute.
# GitHub Actions example
jobs:
fast-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run fast tests
run: cargo test-filter --tag fast
integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run integration tests
run: cargo test-filter --integration
slow-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run slow tests
run: cargo test-filter --tag slow
# Quick iteration - run only fast tests
cargo test-filter --tag fast
# Before commit - run everything except slow tests
cargo test-filter --exclude-tag slow
# Debug a specific area
cargo test-filter --name auth --verbose
# See what tests exist
cargo test-filter --list
cargo test-filter --tag database --list
$ cargo test-filter --tag fast -v
cargo-test-filter v0.1.0
Filters: tags: fast
Project root: /home/user/my-project
Discovered 25 test function(s) in 45.23ms
- api_test::test_fast_endpoint (tags: ["fast", "api"])
- db_test::test_quick_query (tags: ["fast", "database"])
- lib::test_calculation (tags: ["fast", "unit"])
...
Filtered to 3 test function(s)
Running 3 test function(s)...
tests/ and src/ directories for test filescargo test --exactUnlike file-level filtering, this tool identifies which specific test functions match your criteria, so if you have 10 tests in a file and only 2 are tagged "fast", only those 2 will run.
| Feature | cargo test |
cargo test-filter |
|---|---|---|
| Filter by test type | Limited (--lib, --test) |
Yes (--integration, --unit) |
| Tag-based filtering | No | Yes |
| Function-level tags | No | Yes |
| Exclude by tag | No | Yes (--exclude-tag) |
| List tests with tags | No | Yes (--list) |
| Pass-through args | Yes | Yes |
#[tokio::test] and #[async_std::test] detectioncargo test-filter [OPTIONS]
Options:
--integration Run only integration tests
--unit Run only unit tests
--tag <TAG> Filter by tag (comma-separated)
--exclude-tag <TAG> Exclude tests with these tags
--name <PATTERN> Filter by test name pattern
--path <PATTERN> Filter by file path pattern
--list List matching tests without running
--timeout <SECS> Test timeout in seconds (planned)
-v, --verbose Show verbose output
-h, --help Print help
-V, --version Print version
Additional arguments after -- are passed to cargo test.
Contributions welcome! Areas for improvement:
MIT OR Apache-2.0