“Integrated Tests Are A Scam” by J.B. Rainsberger

In retrospective, what he calls integrated tests might be called end-to-end tests

What Are Integrated Tests [end-to-end tests]?

A test whose failure is not easily explicable
i.e. cannot simply identify what the problem occurred i.e. failing test does not reveal the problem, only that there is a vaguely a problem somewhere

Includes end-to-end & system tests

Unit tests should be viewed as isolated tests

Why Do We Write Integrated [End-to-End] Tests?

Tests and System Design

Vicious Cycle of The Scam

  1. We have unit tests
  2. We find a bug despite all unit tests passing
    • this happened because of poor design
  3. We write more integrated tests to cover for poor design
    • instead of correcting the design
  4. We continue with sloppier design
    • more integrated tests means less pressure to correct the design
  5. With sloppier design, we create more bugs
    • sloppy design leads to bugs by itself
    • harder to write the unit tests
  6. We now have less time to write unit tests, and our design now pushes us to write integration tests
    • i.e. more bugs, and yet less unit tests
  7. We’re back at having unit tests and still finding bugs

Explosion of Number of Integrated Tests [End-to-End Tests]

Integration tests grow combinatorically as the number of components/path per component grow:

Contract Testing

Server

Establish the server contract: what must a server accept, what must a server return for a given request.

Establish the contract of the server, rigorously test the component with mocks, stubs.

Client

  1. Establish the client contract: when the client emits a certain request, how does it handle the responses?
    • (given responses conform the contract)
    • Tests for validation, verification of handling of responses
    • e.g. 0, 1, few, many, error
  2. When the client is triggered by its own user, does it produce the correct request? [the client being someone else’s server, how does this jive with the previous segment?]
    • Use mocks, stubs to replace dependencies and set up scenarios (e.g. system time)

[It’s probably possible to write good mocks, stubs because the contract has been very well defined and behaviors entirely fleshed out]

Client Tests and Server Tests Meet

integration_tests_scam_contract_tests_diagram.PNG

[These are component tests then, with the added coordination of one component’s test input being another component’s asserted output]

Better than Integrated [End-to-End] Tests