Tests: function that run before anything else


#1

Is any way to run function before any of tests during cargo test?

Like:

#[test_setup]
fn test_setup() {}

#[test]
fn test1() {}

#[test]
fn test2() {}

and test_setup will run before anything else?


#2

No, the current test runner does not have such functionality. You have to call test_setup yourself in every test method instead.
Some external testing frameworks provide this functionality by wrapping everything into a macro and effectively generating the same code as you could manually do.