Cargo runs unit tests in parallel, so shared fixtures and global state must support concurrent access. Mutable statics are unsafe because aliasing violations or data races can cause undefined behavior. section 6.5
A synchronized test counter
lazy_static! { static ref COUNT: AtomicI32 = AtomicI32::new(0); } A test can then call COUNT.fetch_add(1, Ordering::SeqCst) without directly mutating a mutable static.






































