Developing Java Applications with Spring and Spring Boot
by Claudio Eduardo de Oliveira, Greg L. Turnquist, Alex Antonov
How it works...
The functionality of @WebMvcTest is very similar to the @DataJpaTest annotation we have seen in the previous recipe. The difference is really just a set of components that get initialized during the test bootstrap. Unlike @DataJpaTest, this time there are no database components that are provided for us, but instead we get the WebMvc and MockMvc configurations, which bring all the necessary foundations for initializing controllers, filters, interceptors, and so on. For that reason, we had to add AuthorRepository and PublisherRepository as mock beans into our test code, because otherwise the test would fail to start because Spring Boot would be unable to satisfy the bean dependency that the StartupRunner class has on those two ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access