testing_unit

Crates.iotesting_unit
lib.rstesting_unit
version1.2.1
sourcesrc
created_at2023-05-23 13:19:05.786278
updated_at2023-07-16 09:24:55.893434
descriptionA unit testing library
homepage
repositoryhttps://github.com/taishingi/zuu/tree/master/unit-testing
max_upload_size
id872013
size44,446
Willy Micieli (taishingi)

documentation

https://docs.rs/unit-testing/

README

Lib unit

To run unit test for your rust applications

Installation

cargo add unit-testing

#[cfg(test)]
mod tests {

    use crate::{
        assert_contains, assert_directory_exist, assert_equals, assert_false, assert_files_exist,
        assert_not_contains, assert_true, assert_unequals,
        tdd::unit::{Style::POINT, Unit, NO_PROGRESS},
    };
    use std::env::consts::OS;

    #[test]
    pub fn unit() {
        fn battery_full() -> usize {
            100
        }
        fn battery_not_full() -> usize {
            50
        }

        let mut u = Unit::new("Test the unit framework", NO_PROGRESS, POINT);

        u.ok(true).ko(false);
        u.is_directory("/");
        u.is_file("README.md");
        u.not_full(battery_not_full, 100).full(battery_full, 100);
        u.equals("a", "a").unequals("a", "b");
        u.chaos(false, true);
        u.inferior(50, 500).superior(50, 10);
        u.prime(1).prime(7).prime(11);
        u.pair(2).pair(4).pair(6);
        u.impair(3).impair(9);
        u.contains(OS, "linux").not_contains(OS, "windows");
        u.empty("").not_empty(OS);
        u.end().expect("failed");
    }

    #[test]
    pub fn test_macros() {
        assert_true!("All values must matches true", vec![true, true, true]);
        assert_false!("All values must matches false", vec![false, false, false]);
        assert_directory_exist!(
            "Check if user use linux",
            vec!["/", "/home", "/etc", ".", ".."]
        );
        assert_files_exist!(
            "Check if user use linux",
            vec!["/etc/hosts", "/etc/locale.gen"]
        );

        assert_contains!("Check if user use linux", vec!["linux"], OS);
        assert_not_contains!(
            "Check if user use linux",
            vec!["windows", "ios", "freebsd", "openbsd", "android", "solaris", "netbsd", "macos"],
            OS
        );

        assert_equals!(
            "All value must be equals to linux",
            vec!["linux", "linux", "linux"],
            OS
        );

        assert_unequals!(
            "All os must be only equals to linux",
            vec!["windows", "ios", "freebsd", "openbsd", "android", "solaris", "netbsd", "macos"],
            OS
        );
    }
}
#[cfg(test)]
mod tests {

    use crate::{
        assert_contains, assert_directory_exist, assert_equals, assert_false, assert_files_exist,
        assert_not_contains, assert_true, assert_unequals,
        tdd::unit::{Unit, NO_PROGRESS},
    };
    use std::env::consts::OS;

    #[test]
    pub fn unit() {
        fn battery_full() -> usize {
            100
        }
        fn battery_not_full() -> usize {
            50
        }

        let mut u = Unit::new("Test the unit framework", NO_PROGRESS);

        u.ok(true).ko(false);
        u.is_directory("/");
        u.is_file("README.md");
        u.not_full(battery_not_full, 100).full(battery_full, 100);
        u.equals("a", "a").unequals("a", "b");
        u.chaos(false, true);
        u.inferior(50, 500).superior(50, 10);
        u.prime(1).prime(7).prime(11);
        u.pair(2).pair(4).pair(6);
        u.impair(3).impair(9);
        u.contains(OS, "linux").not_contains(OS, "windows");
        u.empty("").not_empty(OS);
        u.end().expect("failed");
    }


    #[test]
    pub fn test_macros() {
        assert_true!("All values must matches true", vec![true, true, true]);
        assert_false!("All values must matches false", vec![false, false, false]);
        assert_directory_exist!(
            "Check if user use linux",
            vec!["/", "/home", "/etc", ".", ".."]
        );
        assert_files_exist!(
            "Check if user use linux",
            vec!["/etc/hosts", "/etc/locale.gen"]
        );

        assert_contains!("Check if user use linux", vec!["linux"], OS);
        assert_not_contains!(
            "Check if user use linux",
            vec!["windows", "ios", "freebsd", "openbsd", "android", "solaris", "netbsd", "macos"],
            OS
        );

        assert_equals!(
            "All value must be equals to linux",
            vec!["linux", "linux", "linux"],
            OS
        );

        assert_unequals!(
            "All os must be only equals to linux",
            vec!["windows", "ios", "freebsd", "openbsd", "android", "solaris", "netbsd", "macos"],
            OS
        );
    }
}
cargo test -- --show-output
Commit count: 9

cargo fmt