5 Testing subsets of an application with test slices
This chapter covers
- Testing a single layer of the application with test slices, and when to use them
- Using slices in practice, such as
@WebMvcTestand@RestClientTest - Testing a business domain module with Spring Modulith
- Extending existing test slices and creating new slices
When testing applications with the @SpringBootTest annotation, as we’ve done extensively in the previous chapters, Spring Boot Tests loads the full application context, everything from controllers to repositories. For big applications, with hundreds or thousands of beans, or with dependencies that have a long startup time like Hibernate, the impact on test suite execution time can be significant. If your Spring application context takes a full minute to start up on your development machine, then launching a single test will take just as long. With context caching, subsequent tests should be much faster, but one extra minute is already too long when you run tests very frequently. And if you need multiple test contexts, the duration will scale linearly with the number of contexts, or worse.