I have a couple of JUnit tests which need a reference for a expensive resource (a WALA class hierachie), which needs about 30s to be created. I would like to share this reference in my whole test suite.
I thought about a static member in a base class which is laziely initiated with a @BeforeClass
method. After test is run the JVM should be determined anyway.
Is there any other way to accomplish this? Or any other best practice?
Create an explicit test suite (cf. this answer) to run these tests, and use @BeforeClass
and @AfterClass
on the suite itself (cf. this answer):
@RunWith(Suite.class)
@Suite.SuiteClasses({Test1.class, Test2.class})
public class MySuite {
@BeforeClass
public static void initResource() {
MyExpensiveResource.init();
}
@AfterClass
public static void disposeResource() {
MyExpensiveResource.dispose();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With