test-with
A lib help you run test with conditions, else the test will be ignored.
Preamble
This crate provide a workable solution for this issue of rust-lang.
Currently, the condition is checked on build-time not runtime and not perfect, because of this issue of rust-lang. To avoid known issue at this moment, please clean before running test.
; SOME_VAR=true
If you forget to add #[test] flag on the test case, #[test_with] macro will add it for you.
Environment Variable
Run test case when the environment variable is set.
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)].
File/Folder
Run test case when the file or folder exist. This is good for testing with database config.
If you want to check the folder exist or not, please use path.
If the test depends on more than one file or path,
you can write it with multiple file/path,
#[test_with::file(/file1, /file2)] or #[test_with::path(/folder, /file)].
Http/Https Service
Run test case when the http/https service available. This is good for integration testing.
If the test depends on more than one service,
you can write it with multiple service,
#[test_with::http(service1, service2)] or #[test_with::http2(service1, service2)].
TCP socket
Run integration test case when the remote tcp socket is listening.
Remote Server Online Status
Run integration test case when the remote server online. Please note the user running test case should have capability to open socket.