Tag: 防锈

为什么不打印! 在Rustunit testing中工作?

我已经实现了以下方法和unit testing: use std::fs::File; use std::path::Path; use std::io::prelude::*; fn read_file(path: &Path) { let mut file = File::open(path).unwrap(); let mut contents = String::new(); file.read_to_string(&mut contents).unwrap(); println!("{}", contents); } #[test] fn test_read_file() { let path = &Path::new("/etc/hosts"); println!("{:?}", path); read_file(path); } 我这样运行unit testing: rustc –test app.rs; ./app 我也可以运行这个 cargo test 我收到一条消息,说testing通过了,但是println! 从不显示在屏幕上。 为什么不?