This post is about unit testing Spring MVC REST controller using Spring test framework MockMvcBuilders and junit.
The complete source code of this post can be cloned from github.
Libraries Used
Name | Version |
---|---|
Spring MVC | 4.0 |
Spring Test | 4.0 |
Junit | 4.8.1 |
Servlet | 3.0 |
Jackson Mapper | 1.9.13 |
Json Path | 0.8.1 |
Controller Code.
Annotation Name | Usage |
---|---|
@Controller | Marking the class as MVC controller. |
@RequestMapping | Maps the request URL to a class or method. |
@ResponseBody | Return type will be written into response body. |