Time for action – testing REST controllers

Similarly, we can test the REST-based controllers as well. Just perform the following steps:

  1. Open pom.xml and you will find pom.xml under the root directory of the project itself.
  2. You will be able to see some tabs at the bottom of the pom.xml file; select the Dependencies tab and click on the Add button of the Dependencies section.
  3. A Select Dependency window will appear; enter Group Id as com.jayway.jsonpath, Artifact Id as json-path-assert, and Version as 0.8.1. Select Scope as test, click on the OK button, and save pom.xml.
  4. Now create a class called CartRestControllerTest under the com.packt.webstore.controller package in the source folder, src/test/java. Now add the following code to it:
    package com.packt.webstore.controller; ...

Get Spring MVC Beginner’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.