Skip to main content

End-to-end test

A test that drives a request through the real system the way a client would, over HTTP, through the real handler, into the real database, and asserts on the response.

An end-to-end test enters through the same door a real client would, an HTTP request, and asserts on what comes back out, the response. Nothing in between is mocked: not the routing, not the handler, not the database. If any of it is broken, the test fails, regardless of which internal function happens to be at fault.

That's different from a unit test, which calls one function directly and checks its return value, with everything that function depends on faked or stubbed out. A unit test can be green while the system it belongs to is completely broken, if the wiring between pieces is wrong, or if two functions each pass their own tests but disagree about what they hand each other.

The trade-off is cost: an end-to-end test is slower, because it's exercising a real server and a real database instead of a single function call in memory. That's exactly why it's not the first tool to reach for everywhere, only for the endpoints where correctness genuinely depends on the whole chain working together, not just one function in isolation.

Appears in