I am writing a service/integration/api test for a Spring RestController. Rather than using the SpringRunner I am experimenting with running the Spring Application myself from a setup method.
//@RunWith(SpringRunner.class)
//@SpringBootTest(webEnvironment = pringBootTest.WebEnvironment.DEFINED_PORT)
public class MyServiceTest {
@BeforeClass
static public void startServer()
{
SpringApplication.run(MainApplication.class, new String[]{});
}
This works nicely as well, but I was surprised that the Web Server Application is stopped and closed correctly although I had not provided any test cleanup function.
2019-07-03 09:50:20.189 INFO 12544 --- [ Thread-3] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6e0dec4a:
The test lives in src/test/java of a Maven Project.
What is causing the web server to exit at the end of a test run? Is it a documented feature?
When I run the same line in src/main/java the RestController and application stay up ( obviously )
Aucun commentaire:
Enregistrer un commentaire