test-with 0.1.2

A lib help you run test with condition
Documentation

test-with

Crates.io MIT licensed Docs

A lib help you run test with condition

Environment variable

Run test case when the environment variable is set. A solution for this issue of rust-lang.

#[cfg(test)]
mod tests {

    // PWD environment variable exists
    #[test_with::env(PWD)]
    fn test_works() {
        assert!(true);
    }

    // NOTHING environment variable does not exist
    #[test_with::env(NOTHING)]
    fn test_ignored() {
        panic!("should be ignored")
    }
}

Result of cargo test

running 2 tests
test tests::test_ignored ... ignored
test tests::test_works ... ok

test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s

If the test depends on more than one environment variables, you can write it with multiple variables, #[test_with::env(VAR1, VAR2)].

Relating issues