How to test controllers in a REST applications

by Anshul Sahni   Last Updated June 20, 2018 20:05 PM

I'm writing a REST api backend in NODE js, which is based on MVC approach. My api routes directly hit the controllers, which in turn import models which are a wrapper around the methods from a library (DB ORM) called sequelize.

What will be the better approach for writing the unit tests for the controllers,

  1. To include models, with mock DB data, in unit tests of the respective controllers
  2. To somehow mock the models and then unit test my controllers without involving the real models at all.

If the second approach is better how will I achieve writing these types of Unit tests



Related Questions




Is QA/QC more related to proprietary softwares?

Updated January 22, 2019 22:05 PM

What is the best method for testing a web app?

Updated November 23, 2018 13:05 PM