Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created August 11, 2021 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/b5cc228c818d1b19196160ca891b1b33 to your computer and use it in GitHub Desktop.
Save cuongld2/b5cc228c818d1b19196160ca891b1b33 to your computer and use it in GitHub Desktop.
use std::panic;
use rstest::*;
fn setup(){
println!("setup 111");
}
fn teardown(){
println!("teardown 2222");
}
fn run_test<T>(test: T) -> ()
where T: FnOnce() -> () + panic::UnwindSafe
{
setup();
let result = panic::catch_unwind(|| {
test()
});
teardown();
assert!(result.is_ok())
}
fn function_under_test(){
assert_eq!(1,3);
}
#[rstest]
fn example_setup_teardown() {
run_test(|| {
let ret_value = function_under_test();
assert!(false);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment