#test-runner #test-files #file-format #collect

file_test_runner

File-based test runner for running tests found in files

26 releases (11 breaking)

Uses new Rust 2024

0.12.1 Jan 9, 2026
0.12.0 Dec 22, 2025
0.11.1 Dec 19, 2025
0.7.4 Dec 3, 2024
0.7.2 May 31, 2024

#56 in Testing

Download history 1466/week @ 2025-10-04 1492/week @ 2025-10-11 1580/week @ 2025-10-18 2614/week @ 2025-10-25 1756/week @ 2025-11-01 1768/week @ 2025-11-08 1945/week @ 2025-11-15 3523/week @ 2025-11-22 2935/week @ 2025-11-29 3655/week @ 2025-12-06 3789/week @ 2025-12-13 1455/week @ 2025-12-20 1265/week @ 2025-12-27 2195/week @ 2026-01-03 2793/week @ 2026-01-10 3316/week @ 2026-01-17

9,676 downloads per month
Used in 8 crates (4 directly)

MIT license

60KB
1.5K SLoC

file_test_runner

File-based test runner for running tests found in files via cargo test.

This does two main steps:

  1. Collects all files from a specified directory using a provided strategy (file_test_runner::collect_tests).
  2. Runs all the files as tests with a custom test runner (file_test_runner::run_tests).

The files it collects may be in any format. It's up to you to decide how they should be structured.

Examples

Setup

  1. Add a [[test]] section to your Cargo.toml:

    [[test]]
    name = "specs"
    path = "tests/spec_test.rs"
    harness = false
    
  2. Add a tests/spec_test.rs file to run the tests with a main function:

    use std::panic::AssertUnwindSafe;
    
    use file_test_runner::collect_and_run_tests;
    use file_test_runner::collection::CollectedTest;
    use file_test_runner::collection::CollectOptions;
    use file_test_runner::collection::strategies::TestPerFileCollectionStrategy;
    use file_test_runner::RunOptions;
    use file_test_runner::TestResult;
    
    fn main() {
      collect_and_run_tests(
        CollectOptions {
          base: "tests/specs".into(),
          strategy: Box::new(TestPerFileCollectionStrategy {
           file_pattern: None
          }),
          filter_override: None,
        },
        // the run options provide a way to set the reporter or parallelism
        RunOptions::default(),
        // custom function to run the test...
        |test| {
          // * do something like this
          // * or do some checks yourself and return a value like TestResult::Passed
          // * or use `TestResult::from_maybe_panic_or_result` to combine both of the above
          TestResult::from_maybe_panic(AssertUnwindSafe(|| {
            run_test(test);
          }))
        }
      )
    }
    
    // The `test` object only contains the test name and
    // the path to the file on the file system which you can
    // then use to determine how to run your test
    fn run_test(test: &CollectedTest) {
      // Properties:
      // * `test.name` - Fully resolved name of the test.
      // * `test.path` - Path to the test file this test is associated with.
      // * `test.data` - Data associated with the test that may have been set
      //                 by the collection strategy.
    
      // helper function to get the text
      let file_text = test.read_to_string().unwrap();
    
      // now you may do whatever with the file text and
      // assert it using assert_eq! or whatever
    }
    
  3. Add some files to the tests/specs directory or within sub directories of that directory.

  4. Run cargo test to run the tests. Filtering should work OOTB.

Dependencies

~4–6MB
~106K SLoC