3 releases
new 0.1.2 | Feb 20, 2025 |
---|---|
0.1.1 | Feb 16, 2025 |
0.1.0 | Feb 8, 2025 |
#180 in Testing
1,541 downloads per month
41KB
634 lines
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