Reputation: 113
I have some own components, which I start before my Java application. It takes about 30 seconds to start this. In my integration tests, I start my components before the class and all test cases run. My question is, is it possible to run my components not before the test class, but rather before the whole test?
kind regards, bilal
Upvotes: 1
Views: 824
Reputation: 31648
If you use JUnit suites you can use a @BeforeClass
to execute a method before the entire suite runs and an @AfterClass
after the entire suite runs:
@RunWith(Suite.class)
@SuiteClasses(
{
//list your test classes here
}
)
public class IntegrationSuite{
@BeforeClass
public static void setupSuite(){
//do your initialization here
}
@AfterClass
public static void tearDownSuite(){
//...if needed
}
}
Upvotes: 3
Reputation: 3343
If you are using maven you could use the maven-failsafe-plugin. It has a pre-integration-test goal intended for test setup. For an example take a look at Maven Failsafe Plugin: how to use the pre- and post-integration-test phases
Upvotes: 0
Reputation: 2343
Use the @BeforeClass annotation.
Please note that the annotated method has to be static.
@BeforeClass
public static void oneTimeInit() {
System.out.println("It runs only once for all tests in this class.");
}
Upvotes: 2