Screencast: Unit Testing of Spring MVC Controllers - REST API

This video is outdated! If you want to learn how you can write unit tests for a Spring MVC REST API, you should take a look at my updated Spring MVC Test tutorial. It describes how you can write unit tests for a Spring MVC REST API with JUnit 5.

This is the third part of my video tutorial which concentrates on unit testing of Spring MVC controllers. To be more specific, this video talks about the unit testing of REST APIs.

The problem is that writing comprehensive and fast unit tests for these APIs has been troublesome. This video demonstrates how we can solve this problem and write readable, comprehensive, and fast unit tests for a REST API by using the Spring MVC Test framework.

This video teaches us four things:

  • We learn to write unit tests for controller methods which read information from the database.
  • We learn to write unit tests for controller methods which add information to the database.
  • We learn how we can transform DTO objects into JSON bytes and send the result of the transformation in the body of the request.
  • We learn how we can write assertions for JSON documents by using JsonPath expressions.

Watch The Screencast



1 comment… add one
  • Sanju Thomas Nov 11, 2013 @ 19:48

    Thanks. This one helped me to unit test spring mvc code in a better way.

Leave a Reply