Crate after_test

Source
Expand description

The [cleanup] macro iterates over all functions marked as tests in the input token stream and adds a call to the provided function passed as an attribute to the macro.

This macro can be added to the top of your test module and will ensure that the passed cleanup function is called at each test function’s end.

§Example

use after_test::cleanup;

#[cleanup(my_clean_up)]
#[cfg(test)]
mod tests {
    fn my_clean_up() {
       println!("cleaning up resources");
    }   

    #[test]
    fn a_test() {}
}
use after_test::cleanup;

#[cfg(test)]
#[cleanup(|| {println ! ("this will be called at the end of each test")})]
mod tests {
    #[test]
    fn my_test() {}
}

Attribute Macros§

cleanup