简体   繁体   中英

what needs to be initialized for spring-boot integration tests to run standalone

This is what my base test class looks like -

@SpringApplicationConfiguration(classes = ServiceApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port:8084")
public class BaseTestStartService {

    //TODO:add basic service test

}

Not sure what is to be implemented in this base class? What is the correct process? The base class is implemented in the tests classes as -

 @RunWith(SpringJUnit4ClassRunner.class)
    public class TestClass extends BaseTestAPIService{
//add assertions
}

I am trying to implement the correct process so looking for some advice.

Maybe you could give more insight on what exactly your service does and what you want to test, eg REST calls with RestTemplate or direct method calls to the component bean.

Either way, some tips might be interesting:

  • you may need to take advantage of the random port assignment, by specifying server.port:0 and eventually autowiring an int with @Value("${local.server.port}")
    • otherwise the test runner may reuse context and try to start the service a second time, on the same port, when running a second implementation;
  • you can use @Before and @After anotations to setup a common set of fixtures on the base class;
  • the base class should be abstract;
  • the main SpringApplicationConfiguration class is usually called "SomethingTestedHost".

Either way, a common good practice is to keep your services modular and have one different Test Case per @Test annotated method. Judging by your configuration it seems you might have a to large service for which you are structuring the tests. Which could be a good practice if you are using Test Driven Development and plan to segregate the tested service later on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM