Expand description
test_with
provides env, file, path, http, https,
icmp, tcp, root, group, user, mem, swap,
cpu_core, phy_core, executable, timezone macros to help you run
test case only with the condition is fulfilled. If the #[test]
is absent for the test case,
#[test_with]
will add it to the test case automatically.
This crate help you easier make integrating test case and has a good cargo summary on CI server, and will not affect on your binary output when you dependent it as dev-dependency as following.
[dev-dependencies]
test-with = "*"
All features will be opt-in default feature, so this crate will be easier to use, if you using a CI server with really limitation resource and want this crate as slim as possible, you can select the feature you want as following.
[dev-dependencies]
test-with = { version = "*", default-features = false, features = ["net"] }
The solution to have a real runtime condition check, we need to put the test as normal function
as an example, then use cargo run --example
The test-with
need be included as normal dependency with runtime
feature.
And also include the libtest-with
with corresponding features in Cargo.toml
runner and module are for the basic skeleton of the test runner.
runtime_env, runtime_no_env, runtime_file, runtime_path,
runtime_http, runtime_https, runtime_icmp, runtime_tcp,
runtime_root, runtime_group, runtime_user, runtime_mem,
runtime_free_mem, runtime_available_mem, runtime_swap,
runtime_free_swap, [macro@runtime_available_swap], runtime_cpu_core,
[macro@runtime_phy_core], runtime_executable, runtime_timezone
and runtime_ignore_if are used to transform a normal function to a testcase.
[dependencies]
test-with = { version = "*", default-features = false, features = ["runtime"] }
libtest-with = { version = "0.8.1-7", features = ["net", "resource", "user", "executable", "timezone"] }
// write as example in examples/*rs
test_with::runner!(env);
#[test_with::module]
mod env {
#[test_with::runtime_env(PWD)]
fn test_works() {
assert!(true);
}
}
Macros§
- runner
- Provide a test runner and test on each module
- tokio_
runner
Attribute Macros§
- cpu_
core - Run test case when cpu core enough
- env
- Run test case when the environment variable is set.
- executable
- Run test case when the executables exist.
- file
- Run test case when the file exist.
- group
- Run test case when runner in group
- http
- Run test case when the http service exist.
- https
- Run test case when the https service exist.
- icmp
- Run test case when the server online. Please make sure the role of test case runner have capability to open socket
- lock
- Run test case one by one when the lock is acquired It will automatically implement a file lock for the test case to prevent it run in the same time. Also, you can pass the second parameter to specific the waiting seconds, default will be 60 seconds.
- mem
- Run test case when memory size enough
- module
- Help each function with
#[test_with::runtime_*]
in the module can register to run Also you can set up a mock instance for all of the test in the module - no_env
- Ignore test case when the environment variable is set.
- path
- Run test case when the path(file or folder) exist.
- phy_
core - Run test case when physical cpu core enough
- root
- Run test case when runner is root
- runtime_
available_ mem - Run test case when the example running and available memory size enough
- runtime_
cpu_ core - Run test case when cpu core enough
- runtime_
env - Run test case when the example running and the environment variable is set.
- runtime_
executable - Run test case when the executable existing
- runtime_
file - Run test case when the example running and the file exist.
- runtime_
free_ mem - Run test case when the example running and free memory size enough
- runtime_
free_ swap - Run test case when the example running and free swap enough
- runtime_
group - Run test case when runner in group
- runtime_
http - Run test case when the example running and the http service exist.
- runtime_
https - Run test case when the example running and the http service exist.
- runtime_
icmp - Run test case when the example running and the server online. Please make sure the role of test case runner have capability to open socket
- runtime_
ignore_ if - Ignore test case when function return some reason
The function should be
fn() -> Option<String>
- runtime_
mem - Run test case when the example running and memory size enough
- runtime_
no_ env - Ignore test case when the example running and the environment variable is set.
- runtime_
path - Run test case when the example running and the path(file or folder) exist.
- runtime_
phy_ cpu_ core - Run test case when physical core enough
- runtime_
root - Run test case when runner is root
- runtime_
swap - Run test case when the example running and swap enough
- runtime_
tcp - Run test case when the example running and socket connected
- runtime_
timezone - Run test case when the example running within specific timzones.
- runtime_
user - Run test case when runner is specific user
- swap
- Run test case when swap size enough
- tcp
- Run test case when socket connected
- timezone
- Run test case when the timezone is expected.
- user
- Run test case when runner is specific user