chr*_*mue 34 unit-testing rust
一个模块包含多个测试,如下所示:
#[cfg(test)]
mod tests_cases {
    /*
    #[test]
    fn test_1() {
        let a = 1;
        let b = 2;
        println!("{},{}", a, b);
        assert_ne!(a, b);
    }
    */
    #[test]
    fn test_2() {
        let c = 1;
        let d = 1;
        println!("currently working on this: {},{}", c, d);
        assert_eq!(c, d);
    }
}
当使用输出可见 ( cargo test -- --nocapture) 进行第二个测试时,我不想看到第一个测试的输出。
是否有一个选项可以禁用注释的单元测试?或者是否可以选择只运行第二个单元测试?
chr*_*mue 63
另一种选择是添加该#[ignore]属性。
#[ignore]
#[test]
fn test_1() {
    let a = 1;
    let b = 2;
    println!("{},{}", a, b);
    assert_ne!(a, b);
}
这会为测试结果添加一个漂亮的忽略颜色。
test tests::test_1 ... ignored
test tests::test_2 ... ok
test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.03s
资料来源: 除非特别要求,否则忽略一些测试