Unit testing versus Express.js application integration testing

I am writing tests for an Express.js application and I have no idea how to choose between unit tests and integration tests.

I am currently experimenting with:

unit tests - using Sinon for stubs / mocks / spies and Injects for dependency injection for modules. with this approach i have to stub MongoDB and other external methods.

I thought about unit testing the individual routes and then using an integration test to make sure the correct routes were actually called.

integration tests - using Supertest and Superagent, much less code to write (no need to mock / stub anything), but a test environment (databases, etc.) must exist

I am using Mocha to run both test styles.

how to choose one of two different approaches?

+3


source to share


1 answer


You should probably do both. Unit test every non-helper method that does non-trivial work. Run it all through a few integration tests. If you find that you have tons, tons and tons of layouts and stubs to do, this is probably a sign for refactoring.



+1


source







All Articles