The Test Spectrum

The test pyramid is a fairly popular idea, but it's message is off. The pyramid presents the idea that the types of tests are not equal. Unit tests are the foundation and test suites should have a lot of them. There will be fewer integration tests and even fewer acceptance (end-to-end) tests.

Test Pyramid

Like all one size fits all advice, the test pyramid is only useful for certain classes of applications that have a lot of core functionality that exists independently of the host platform in which the application resides. To put it another way: with a simple CRUD application that relies, for the most part, on a framework with very little external code there's a good chance unit tests simply aren't that useful.

Instead we should look at tests is on a spectrum from isolation to integration.

Test Spectrum

Isolation here means pulling out and isolating components with test doubles in place of collaborators. Integration is the opposite: using real collaborators and real objects. With a completely isolated test, a test double is used for everything (maybe even the filesystem). A fully integrated test would use the application from end to end.

The lines between the types of tests become, necessarily, blurred. It doesn't matter what type the test is, it matters that it will fail if something is broken. If there's a lot of core code outside of whatever host platform the application is using, unit tests become more valuable to test those things in isolation. With a CRUD app like the one described above it's more important that tests verify the application is using the framework correctly. Using real objects and functions from the framework or host platform is the best way to accomplish that.

Somewhere along the test spectrum is a level of integration that's the most useful for a given application. That's the level of integration where most of the application's tests should be.

Test Spectrum

No one type of test is better in the global scope. What matters is the test's usefulness in the context of the application. Sometimes writing a more integrated test means a more useful test. Sometimes integration tests are a scam.

#