-1

I want to write unit test case for my node mysql rest api app.

The api call procedure:

route -> controller -> resources(models/Mysql) -> formatters -> controller -> response Factory. Now I want to ask how can I write unit test cases for a route with code coverage.

1 Answers1

0

The unit test is not something that you are asking for. Unit Test is something testing smallest unit of your code. Eg. If you have multiple functions to satisfy your request and you are writing test cases to validate each method is unit test.

If you are writing the test code to for your route is called feature test or integration testing.

Please check this link Unit tests vs Functional tests

Once, you have understood the concept of unit testing and integration testing, There are few testing frameworks is available like chai, mocha you can start with these packages.

narayansharma91
  • 2,273
  • 1
  • 12
  • 20
  • Thanks for you quick reply. I got the diff between Unit and Integration test. Now Suppose I am writing controller function test case which have a call to mysql, now return some data. So how can I do that. Will I need to do mysql stuff also. Thanks. – Yogendra Singh Apr 08 '19 at 13:07