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 ...
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