There are times when individual controller testing is preferable to loading the whole context into the Spring TestContext framework. This mechanism is only applicable to controllers that have fewer dependencies on other beans of the container, which makes them easy to test individually.
Once again, open the Maven ch03
project and add the following standalone controller test cases.
Let us test some existing controllers in ch03
by performing the following steps:
- Create another test class inside
org.packt.dissect.mvc.test
without loadingWebApplicationContext
and configureMockMvc
to test onlySimpleController
of this project:
import static org.springframework.test.web.servlet.request. MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request. MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result. MockMvcResultHandlers...