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

I write my spring-boot tests using rest-sure and these annotations in 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{
}

The question here is: if I need to execute both java classes in a command one by one in the form of performing integration tests, then there is a way that I can have annotation in only one class, so that after the service is started and all tests can run or not, and should I put annotations in all classes?

+4
source share
1 answer

Actually, you can

You can do this using inheritance:

Class with all configuration

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

}

The first test class, extending from WebAppConfigTest

public class MyTestClass extends WebAppConfigTest {
}

, WebAppConfigTest

public class MyTestClass extends WebAppConfigTest {
}
+2

All Articles