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

后端 未结 5 830
天涯浪人
天涯浪人 2020-11-30 17:09

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) {
    l         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 17:56

    To include print outs with println!() and keep colors for the test results, use the color and nocapture flags in cargo test.

    $ cargo test -- --color always --nocapture
    

    (cargo version: 0.13.0 nightly)

提交回复
热议问题