About Petri Kainulainen
Writing unit tests for Spring MVC controllers has traditionally been both simple and problematic. Although it is pretty simple to write unit tests which invoke controller methods, the problem is that those unit tests are not comprehensive enough. For example, we cannot test controller mappings, validation and exception handling just by invoking the tested controller method.
Spring MVC Test solved this problem by giving us the possibility to invoke controller methods through the DispatcherServlet. This is the first part of my tutorial which describes the unit testing of Spring MVC controllers and it describes how we can configure our unit tests. Let’s get started.
Getting the Required Dependencies with Maven
We can get the required dependencies by declaring the following testing dependencies in our pom.xml file:
- JUnit 4.11
Source : http://www.javacodegeeks.com/2013/07/unit-testing-of-spring-mvc-controllers-configuration-2.html