小编chr*_*mue的帖子

如何使用属性禁用 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);
    }
}

Run Code Online (Sandbox Code Playgroud)

当使用输出可见 ( cargo test -- --nocapture) 进行第二个测试时,我不想看到第一个测试的输出。

是否有一个选项可以禁用注释的单元测试?或者是否可以选择只运行第二个单元测试?

unit-testing rust

34
推荐指数
2
解决办法
1万
查看次数

标签 统计

rust ×1

unit-testing ×1