This chapter covers the test module of Spring and the APIs used for unit and integration testing Spring applications. The following topics are covered here:
Spring's
TestContext
framework andSpringJUnit4ClassRunner
Spring profiles
Mocking environments with
MockEnvironment
andMockPropertySource
Mocking a JNDI lookup with
SimpleNamingContextBuilder
andExpectedLookupTemplate
Testing with
ReflectionTestUtils
Exploring Spring annotations for unit testing; the annotations covered are
@ContextConfiguration
,ApplicationContextInitializer
,@WebAppConfiguration
,@ContextHierarchy
,@ActiveProfiles
,@ProfileValueSourceConfiguration
,@TestPropertySource
,@DirtiesContext
,@TestExecutionListeners
,@IfProfileValue
,@Timed
, and@Repeat
Unit testing Spring MVC with
MockHttpServletRequest
,MockHttpSession
, andModelAndViewAssert
, as well as Spring beans with request scope and Spring beans with session scopeMocking a servlet container with
MockMvc
Transaction management with...