MSTest Unit TestCase

Feb 27 2023 10:27 AM

Am writing unit test cases (MSTest) for a webAPI method.

  1. Do I have to directly create a new instance of the controller and call the webAPI method to obtain the response? & then keep an Assert statement to check if the value inside the response matches with a value? or
  2. Do I have to create an interface for the controller and then mock the controller class and the input values and call the webAPI method to obtain the response? & then keep an Assert statement to check if the value inside the response matches with a value?

If so how to create an interface of the controller and create mock of the same? (ex: controller name: ABCController , API Method to call : ABCGet() )


Answers (2)