Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
About the Author
About the Reviewers


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 as they will be handled at runtime, and performed real Spring integration and transaction management with the @Transactional, @TransactionConfiguration, and @Rollback annotations.

The next chapter focuses on how to mock Spring beans with Mockito. This...