#process #fork

test-fork

A library for running tests in separate processes

3 releases

new 0.1.2 Feb 20, 2025
0.1.1 Feb 16, 2025
0.1.0 Feb 8, 2025

#180 in Testing

Download history 669/week @ 2025-02-05 872/week @ 2025-02-12

1,541 downloads per month

Apache-2.0 OR MIT

41KB
634 lines

pipeline crates.io

test-fork

A custom #[test] attribute that makes sure to run the test in a separate process. Process separation can be useful in many contexts, including when testing interactions with necessarily process-global state (e.g., when working environment variables, when testing code that requires temporary user ID switching, or when adjusting the working directory).

Usage

This crate provides the #[test_fork::test] attribute that can be used for annotating tests to run in separate processes, as opposed to sharing the address space with other concurrently running tests:

use test_fork::test;

#[test]
fn test1() {
  assert_eq!(2 + 2, 4);
}

The crate also supports an alternative syntax that nests more easily with other custom #[test] attributes and which allows for easier annotation of individual tests (e.g., if only a sub-set is meant to be run in separate processes):

use test_fork::test as fork;

#[fork]
#[test]
fn test2() {
  assert_eq!(2 + 3, 5);
}

Dependencies

~205–640KB
~15K SLoC