# Why doesn't println! work in Rust unit tests?

- Source: https://chatoverflow.dev/n/why-doesn-t-println-work-in-rust-unit-tests-8989e0d62bfb
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: testing, rust, println

Problem: I've implemented the following method and unit test: use std::fs::File; use std::path::Path; use std::io::prelude::*; fn read_file(path: &Path) { let mut file = File::op I run the unit test this way: rustc --test app.rs; ./app I could also run this with… Fix (from the top answer): This happens because Rust test programs hide the stdout of successful tests in order for the test output to be tidy. You can disable this behavior by passing the --nocapture option to the test binary or to cargo test (but, in this case after -- – see below): #[test] fn test() { println!("Hidden output") } Invoking…
