#setup #teardown #api #test

test_suite_rs

Provides a macro to create a test suite with a setup and teardown function

4 releases

0.1.4 Aug 1, 2023
0.1.3 May 4, 2023
0.1.2 May 3, 2023
0.1.1 Apr 24, 2023
0.1.0 Apr 21, 2023

#245 in Testing

Download history 7/week @ 2024-03-09 8/week @ 2024-03-16 1/week @ 2024-03-23 18/week @ 2024-03-30 32/week @ 2024-04-06 3/week @ 2024-04-13 4/week @ 2024-05-11 50/week @ 2024-05-25 203/week @ 2024-06-01 1/week @ 2024-06-08

219 downloads per month

Custom license

11KB
142 lines

test_suite_rs

Provides a macro to create a test suite with a setup and teardown function. Each test block generates a separate test function that will run setup and teardown functions if provided.

Example

use test_suite_rs::test_suite;

fn setup() -> (i32, String) {
    (43, "my_string".to_owned())
}

fn teardown() {}

test_suite! {
    - name: test_mod
    - setup: setup(i32, String)
    - teardown: teardown

    test should_return_true(nbr, my_string) {
        assert_eq!(nbr, 43);
        assert_eq!(&my_string, "my_string");
    }

    test should_return_false {
        assert!(true);
    }
}

Generates the following code (simplified):

mod test_mod {
    use super::*;

    #[test]
    fn should_return_true() {
        let (nbr, my_string) = setup();

        assert_eq!(nbr, 43);
        assert_eq!(&my_string, "my_string");
        teardown();
    }
    
    #[test]
    fn should_return_false() {
        assert!(true);
    }
}

lib.rs:

Provides a macro to create a test suite with a setup and teardown function. Each test block generates a separate test function that will run setup and teardown functions if provided.

Example


use test_suite_rs::test_suite;

fn setup() -> (i32, String) {
    (43, "my_string".to_owned())
}

fn teardown() {}

test_suite! {
    - name: test_mod
    - setup: setup(i32, String)
    - teardown: teardown

    test should_return_true(nbr, my_string) {
        assert_eq!(nbr, 43);
        assert_eq!(&my_string, "my_string");
    }

    test should_return_false {
        assert!(true);
    }
}

Generates the following code (simplified):

 # fn setup() -> (i32, String) {
 #    (43, "my_string".to_owned())
 # }

 # fn teardown() {}

 mod test_mod {
 #   use std::assert_eq;
     use super::*;

     #[test]
     fn should_return_true() {
         let (nbr, my_string) = setup();

         assert_eq!(nbr, 43);
         assert_eq!(&my_string, "my_string");
         teardown();
     }
 }

No runtime deps