Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-boot : how to execute multiple test classes by just starting the service once using rest-assured

I am writing my spring-boot tests using rest-assured and these annotations on the test class -

java class 1:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ApplicationSErvice.class)
@WebAppConfiguration
@IntegrationTest("server.port:8083")
public class MyTestClass{
}

java class 2:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ApplicationSErvice.class)
@WebAppConfiguration
@IntegrationTest("server.port:8083")
public class MyTestAnotherClass{
}

Question here is , if I have to execute both the java classes on the teamcity one after the other in the form of executing integration tests,then is there a way that I can have the annotation just in one class so that once the service is up and running all the tests can execute or there is no way and I have to put the annotations in all the classes?

like image 281
worrynerd Avatar asked May 13 '15 21:05

worrynerd


1 Answers

Actually, you can

You can do it using inheritance:

Class with all the configuration

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ApplicationSErvice.class)
@WebAppConfiguration
@IntegrationTest("server.port:8083")
public class WebAppConfigTest {

}

First test class extending from WebAppConfigTest

public class MyTestClass extends WebAppConfigTest {
}

Second test class extending from WebAppConfigTest

public class MyTestClass extends WebAppConfigTest {
}
like image 169
Eddú Meléndez Avatar answered Sep 20 '22 07:09

Eddú Meléndez