8

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?

worrynerd
  • 705
  • 1
  • 12
  • 31

1 Answers1

11

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 {
}
Eddú Meléndez
  • 6,107
  • 1
  • 26
  • 35
  • 1
    This really comes in handy when you want to test some Spring Data repositories with in memory test DB. Thank you ! By the way, WebAppConfigTest should not be empty, so I've put a NotNull test on my ApplicationContext in it. – JR Utily May 20 '15 at 15:34
  • 1
    @JRUtily you can call the class AbstractSomethingTest or avoid the word test so you don't have the "empty" problem – rick Oct 24 '16 at 14:27