0

I am using Express to build a REST API. The code is divided, as should be, in Routes/Models/Controllers (no views, it's just JSON)

The controllers take care of the logic : they make request to the database and build the responses. To me, this is the main thing to test in my application.

Now, how should I test my controllers ?

I have read that writing atomic tests is the best way to go, so I guess I should clear the database, run migrations and seed the database before every single test (which is composed of making a request to the controller + checking the response)... but this takes ages, even for a very small number of tests ! If I do it this way, hooking the tests to git seems a really bad idea, and the whole idea of testing them breaks down.

Magix
  • 4,989
  • 7
  • 26
  • 50
  • 1
    Looks like you muss Integration tests and Unit tests. Unit tests should be tested in isolation. Test UI logic using UI testing frameworks, same goes to other levels(you can use different libraries to mock objects). If test's are runing in isolation they will be fast.... – Alexandr Jan 28 '18 at 12:38

1 Answers1

1

You can test your REST API using Postman.

Supraj V
  • 967
  • 1
  • 10
  • 19
  • I already use Insomnia for manual end-to-end tests, but Postman doesn't help in testing controllers specifically. Thanks for the advice anyway, the tool is great ! – Magix Jan 28 '18 at 13:06