Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditionally skip tests based on runtime information?

Tags:

rust

Is it possible to programmatically skip some tests based on runtime information? For example, I would like cargo test to emit something like

test my_test ... skipped

instead of

test my_test ... ok

when cond() is evaluated to false in the following test:

#[test]
fn my_test() {
    if !cond() {
        // Mark the test as skipped. How?
        return;
    }

    // The actual test that works only when cond() returns true.
}

In other words, I am looking for a Rust alternative of unittest.skipTest() in Python (more information).

like image 658
s3rvac Avatar asked Apr 22 '17 09:04

s3rvac


People also ask

Can you ignore a test based on runtime information?

OK, so the @Ignore annotation is good for marking that a test case shouldn't be run. However, sometimes I want to ignore a test based on runtime information. An example might be if I have a concurrency test that needs to be run on a machine with a certain number of cores.

How do you ignore test cases from running?

Now, update TestJunit in C:\>JUNIT_WORKSPACE to ignore all test cases. Add @Ignore at class level. Compile the test case using javac. Now run the Test Runner, which will not run any test case defined in the provided Test Case class.


1 Answers

There is nothing built in for this; tests only succeed or fail.

The built in test runner is very minimal.

like image 136
Steve Klabnik Avatar answered Oct 24 '22 19:10

Steve Klabnik