To run unit test for your rust applications
sh
cargo add unit-testing
```toml
[package]
name = "
[lib]
name = "
[[bin]] name = "unit-testing" path = "src/bin.rs"
[dependencies] coloredtruecolor = "0.1.0" mockall = "0.11.3" progressbar = "1.0.3" unit-testing = "0.3.3" ```
```rust use unit::zuu::Unit; use unit::{assertbetween, assertdefined, assertempty, assertexist, assertfailure, assertfalse, asserthas, asserthasnot, assertinferior, assertnotexist, assertsuccess, assertsuperior, assert_true, theorem, unit}; fn kool() -> bool { return false; }
fn look() -> bool { return true; }
fn s() -> i32 { return 0; }
fn f() -> i32 { return 1; }
fn get_fans() -> i32 { return 5; }
fn main() {
assert_false!(vec!{kool(),false,false});
assert_true!(vec!{look(),true,true});
assert_empty!(vec!["","",""]);
assert_defined!(vec!["a","b","c"]);
assert_exist!(vec!["/","/home","/var","/dev"]);
assert_not_exist!(vec!["\\C:Users"]);
assert_has!(
"Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.",
vec!["Rust","runtime","or","fast","garbage collector","easily"]);
assert_has_not!(
"Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.",
vec!["C++","go","C","php","complex"]);
assert_success!(vec![
0,0,0,0,0,0,0,0,0,0
]);
assert_failure!(vec![1,1,1,1,1,1,1,1,1,1,1]);
theorem!("Check pythagore theorem",
vec![
4*4 + 3*3 == 5*5,
6*6+8*8 == 10*10,
8*8 + 15*15 == 17*17
]
);
assert_superior!(50,vec![
500,100,600,200,300
]);
assert_inferior!(50,vec![
40,30,20,10,5,2,1
]);
assert_between!(50,100,vec![
60,70,80,90,95,55,66,88
]);
assert!(unit!("Test the unit framework")
.failure(&f).success(&s).expect(kool(), false).expect(look(), true).expect(f(), 1).expect(s(), 0)
.equals(&s, 0)
.equals(&f, 1)
.success(&s).failure(&f)
.contains("I love linux", "linux")
.finnish("I love linux", "linux")
.begin("Linux it's the best", "Linux")
.contains("Linux is superb", "Linux")
.different("linux", "windows")
.chaos("windows love linux", &kool)
.theory("windows love linux", &look, true)
.between(&get_fans, 1, 10)
.inferior(&get_fans, 10)
.superior(&get_fans, 1)
.exist("/home")
.empty("")
.not_empty(" ")
.has("window love linux", "linux")
.defined("linux")
.not("linux", "windows")
.end()
.is_ok());
} ```
shell
./target/debug/unit-testing