Learn to write tests which are easy to read and write: get started with Spock Framework.

Screencast: Unit Testing of Spring MVC Controllers – REST API

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

About the Author

Petri Kainulainen is passionate about software development and continuous improvement. He is specialized in software development with the Spring Framework and is the author of Spring Data book.

About Petri Kainulainen →

1 comment… add one
  • Thanks. This one helped me to unit test spring mvc code in a better way.


Leave a Comment