chapter two
2 Testing a Spring Boot "Hello World" application
This chapter covers
- Interacting with your application inside a
@SpringBootTest - Factoring common setup with JUnit
- Decoupling from external dependencies with mocks
- Deciding when (not) to use
@SpringBootTest
When you create a project on https://start.spring.io, also known as Spring Initializr, you get testing libraries bundled in, as we mentioned in the previous chapter. There is also a test class in the zip file containing your project, ready to run. It contains a single (empty) test method, and the only thing it verifies is that the application can start. This has value on its own, as it validates your Spring dependency graph and your Spring Boot properties. Having this test class also makes it easy to add your own tests without having to make too many decisions: the next obvious step is to add another method to this test file.