How to disable a unit test in rust with an attribute?

Another option is to add the #[ignore] attribute.

#[ignore]
#[test]
fn test_1() {
    let a = 1;
    let b = 2;
    println!("{},{}", a, b);
    assert_ne!(a, b);
}

This adds a nice colored ignored to the test results.

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

Source:
Ignoring Some Tests Unless Specifically Requested

Leave a Comment