Skip to content

Instantly share code, notes, and snippets.

@sleepyfox
Last active July 14, 2020 12:44
Show Gist options
  • Save sleepyfox/cfa6bab8e3d46b3cd7caef25e77c5435 to your computer and use it in GitHub Desktop.
Save sleepyfox/cfa6bab8e3d46b3cd7caef25e77c5435 to your computer and use it in GitHub Desktop.
The exponential horn of testing

The exponential horn of testing

drinking horn

My favourite type of horn, a Viking drinking horn from Horns of Odin.

Inspired by Seb Rose's tweet about 'Eviscerating the Testing Pyramid', which, although containing some reasonable thoughts, I cannot take seriously due to his bizarre choice of language.

"Hey, Rogue boy! You call that an Eviscerate?"
"But Kungen, I crit for over 10,000!"

Nubcake news, from the late TotalBiscuit

To set your mind at rest, no pyramids (or goats q.v. OED) will be disembowelled during the course of this discussion.

test pyramid

So, this article rests on the premise that despite being named by its inventor, Mike Cohn, as the 'testing pyramid', he drew it as a triangle, and afterwards everyone who writes on the topic does so also. Curiously enough if you Google test pyramid you get hundreds of images of triangles.

Don't get me wrong, I'm not criticising, drawing tools are for the most part rubbish and most of us aren't artistically gifted, so if it's easier to draw a triangle in Google Docs then that's what we do. Simplest possible thing that might work, right?

The downside is that when we have a diagram like Mike's original above, it makes it seem that perhaps we have one UI test to two service tests to three unit tests, or thereabouts. Before I go on I'd like to call them 'end-to-end' (E2E) tests, rather than UI tests, as we may not have a user interface in our system.

In other words the base of the triangle at any given height is proportional to the distance from the apex. This visual metaphor allows us to build a mental model that says that providing there are less E2E tests than service tests, and less service tests than unit tests, then we're matching the model. We'll call this two-dimensional model the linear model, because this is how the number of tests scales, where x is the number of tests at one level, and y is the number of tests at a level above and h represents the depth from the apex.

Linear model: x = hy

So if the height h goes from 1 to 2 to 3 we get 1 E2E test to 2 service tests to 3 unit tests.

Nothing could be further from the truth. With the three-dimensional 'pyramid' model we get a different relationship between the area at any given height and the distance to the apex. We'll call this the polynomial model:

polynomial model: x = h^2y

So if the height h goes from 1 to 2 to 3 we get 1 E2E test to 4 service tests to 9 unit tests.

pyramid

This is somewhat closer, but doesn't really quite get to the crux of the matter. The actual model that more closely resembles what we need should have the bare minimum of E2E tests, quite a number of service tests and the vast majority should be unit tests.

Exponential model: x = 10^hy

So if the height h goes from 1 to 2 to 3 then we have 1 E2E test to 100 service tests to 10,000 unit tests.

There is a physical object which has these properties, it is called an exponential horn. The exponential horn has the property that the surface area at any depth of the horn is proportional to the exponent of the height from the apex. It also has some interesting acoustic properties (see above link), but I'll leave those for another day.

exponential horn

So, now you know. It is less the 'testing triangle' or 'testing pyramid' but rather the 'exponential horn of testing'. I wonder if the name will catch on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment