API Testing
ELI5 — The Vibe Check
API testing is checking that your backend endpoints work correctly — sending requests with different data and making sure you get the right responses, status codes, and error messages back. No UI needed. Tools like Postman, Insomnia, or Supertest let you test APIs directly.
Real Talk
API testing validates that HTTP endpoints behave correctly by sending requests and asserting on responses (status codes, headers, body schema, response time). It can be done manually (Postman), programmatically (Supertest, Axios + Jest), or contract-driven (Pact).
Show Me The Code
// Supertest example
import request from 'supertest';
import app from '../app';
describe('GET /users/:id', () => {
it('returns user when found', async () => {
const res = await request(app).get('/users/1');
expect(res.status).toBe(200);
expect(res.body).toMatchObject({ id: 1, name: expect.any(String) });
});
it('returns 404 when not found', async () => {
const res = await request(app).get('/users/99999');
expect(res.status).toBe(404);
});
});
When You'll Hear This
"Write API tests for every endpoint before we go to production." / "API testing caught that the /users endpoint wasn't validating the email format."
Related Terms
Assertion
An assertion is your test saying 'I DEMAND this is true!'. It's you checking that the result is what you expected.
Contract Test
A contract test checks that two services agree on how they'll talk to each other — what requests look like, what responses look like.
End-to-End Test (E2E)
An end-to-end test is like hiring a robot to be a user.
Integration Test
If a unit test checks one LEGO brick, an integration test checks that two bricks actually snap together correctly.