Can we consider sending a request to an endpoint a unit or an integration test?
import lib from 'testing-lib';
// ...
const { testClient, expect } = lib;
const response = testClient
.request(app)
.get('/test/endpoint/');
// ...
expect(response).fulfills.some.condition.ok
I have a feeling that this is an integration test because it will ascertain that every piece, that is in between the request going out and the response coming back, is working as expected. I need to know if my vague understanding is correct or if I am missing some details.
I'm gonna go with neither. It's a functional test.
Unit tests test units of code. Hence the name. A unit of code is typically a function, class or module of some sort.
Integration tests validate that our units of code work together as expected. But it's still just testing the code.
Functional tests test the actual software in a deployed state through exposed interfaces.
So, in Node, a unit test might be testing one of your JavaScript modules by itself and mock out the dependencies. An integration test would be testing that your modules work together and would mock out only the extreme edges of the system. And a functional test would test that a particular endpoint works over HTTP and wouldn't mock anything.
I'll add that I encourage sticking to DRY principles while writing your tests. If you have a unit test that validates a thing, you don't need to validate that in an integration test. Just validate that the units work together as expected. And the same with functional tests. Don't validate the integration, that the units work together. Validate that the endpoints map to the expected behavior.
Yeap this is more an integration test.
Unit tests are more like the functional business logic test. For an example after your route handler (controller) received the request and calls Service to handle the logic. Test of that logic is a unit test.
Integration test is checking if data-flow works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With