Summary
This chapter covered every aspect of unit testing the Spring applications. It started with the TestContext
framework and explored the JUnit 4 enabled SpringJUnit4ClassRunner
.
We also looked at Spring profiles to work with a different set of configuration files, explored the Spring Environment
interface, and how to mock the Environment
interface with MockEnvironment
and MockPropertySource
. Moreover, we used the ReflectionTestUtils
methods to access private fields of the Spring beans, saw the provided usage and examples of Spring annotations for testing, unit tested the MVC application with MockHttpServletRequest
, MockHttpSession
, and ModelAndViewAssert
. We mocked the servlet container with MockMvc to handle actual requests and responses ...
Get Mockito for Spring now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.