Created
August 11, 2021 11:31
-
-
Save cuongld2/b5cc228c818d1b19196160ca891b1b33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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