Unearthing the Mathematics of the Test Pyramid

When the topic of what and how to test comes up, there is a really good chance that the Test Pyramid is going to be referenced by someone in that conversation. For something so prevalent how much can we really say we know about what it is the test pyramid is telling us.

We know that as we progress up the pyramid each level is smaller than the next, but how much smaller? How does adding more layers change the dynamics of the distribution of tests. To unearth answers to questions like these let's dig into the mathematics of the test pyramid.

test pyramid

Image By Mike Cohn source: Mountain Goat Software

By treating the test automation pyramid as a triangle we can use elements of geometry and trigonometry to find the size of each level. To figure this out, we'll start out by breaking the pyramid down into 3 separate triangles. We will determine the area of each triangle, then use a slicing technique to determine each level's size.

pyramid slices

The first step we need to do is find the total area for a triangle using these dimensions from the great pyramid:

giza dimensions

Image By TheTimes.co.uk: Source

Base Length Height Base Angle
230 meters 147 meters 51.5 degrees

Using those dimensions we can find the total area for the triangle that makes up one side of the pyramid.

giza area

Working from the top (UI level) down we can find out how large each level is and what percent of the whole pyramid it captures.

UI Level

Dividing the height of the great pyramid evenly into 3 sections means our top section, the UI layer, is 49 meters tall. Now we can use some trigonometry to help us find the missing lengths that we need to determine the area of this layer. To help us, we are going to split this layer vertically down the middle to create 2 identical right triangles.

If you studied trigonometry before you may remember the mnemonic device SOH-CAH-TOA to help know which trigonometric function to use. Since we need to find out how wide this layer is, and we know the base angle of the great period and the height, we can use the SOH part of SOH-CAH-TOA.

The sine of base angle equals the length of the side opposite the base angle divided by the hypotenuse.
ui sine 1

To find the hypotenuse length, we manipulate the equation to find that the length of the hypotenuse equals about 62.6 meters.

ui - hypotenuse

Now we know the height of the triangle and the length of the outside edge. This is the reason we sliced the pyramid vertically to create 2 right triangles. The next step is to use the Pythagorean Theorem to get our base length. By taking the theorem, and plugging in the numbers we know, we get:

ui pythagorean

To find our Base length we manipulate the equation so that it becomes:

base length ui

That solves all the sides of one of the right triangles we created, which means we know half the base length, so to get the full length we multiply by 2 to get 77.92. Now we have all the sides of our top layer so we can determine the area.

ui area

The UI layer of the pyramid is 1909.4 or about 11.3% of the total pyramid.

Service Level

We are going to use the same process to find the area of the middle layer, only this time we will use a height of 98 meters which represents from the base of the second layer up to the top of the pyramid.

service layer 1

To find our Base length it becomes:

service base length

That solves all the sides of one of the right triangles we created, which means we know half the base length, so to get the full length we multiply by 2 to get 155.84. Now we have all the sides of our top layer so we can determine the area.

This creates a triangle with a total area of:

service triangle area

Now we subtract the top triangle's area from this triangle to find the area of the service layer of the pyramid.

service layer area

The service layer of the pyramid is about 33.9% of the total pyramid.

Unit Level

To find the area of the unit layer we subtract the total area of the service and UI layers from the total area of our test pyramid

unit layer area

The service layer of the pyramid is about 54.8% of the total pyramid.

Level UI Service Unit
area 1909.4 5726.76 9268.84
% of total 11.11% 33.21% 55.68%

Different Pyramids

There's no proof that the test automation pyramid is meant to follow the dimensions of the Great Pyramid at Giza. In order to gather more data points, let's do the math using two other special types of triangles using different dimensions.

Equilateral Triangle

equilateral triangle

An equilateral triangle is a triangle that has the same length for all three sides. The math for an equilateral triangle is more simple because all the side lengths and angles are the same. For this triangle we'll use a side length of 10. The first step is to determine the total area of this triangle, and because there is a formula for finding the area of an equilateral triangle all we need to do is plug in our side length.

eqilateral area

To start determining the area of the levels of an equilateral triangle we start by using the equation to find the height of an equilateral triangle. For a triangle that has sides that are 10 meters long the height would be 8.66 meters.

equilateral height

To get three equal height levels we divide that by three, so each level is ~2.89 meters high.

Now we know the height, and all angles in an equilateral triangle are 60 degrees so we have all the information we need to use the same trigonometric function used for the great pyramid to find how long the side length of the UI level.

equilateral side length

Since we have figured out the length of the sides of the UI level triangle we can plug it into the formula for finding the area of an equilateral triangle

ui equilateral area

The UI level is about 11.1% of the total pyramid. To figure out the remaining levels it's a matter of repeating these steps for the service level and then using the same method of subtracting the triangles as we did for the great pyramid.

Level UI Service Unit
area 4.8 14.46 24.04
% of total 11.1% 33.4% 55.5%

45-45-90 Triangle

45 45 90

A 45 45 90 triangle is also known as a right isosceles triangle. This a triangle where two angles are 45 degrees and the other angle is 90 degrees. It's also the shape of a square cut in half diagonally. Similar to the equilateral triangle, there are known equations we can use that make the math a little easier. For this triangle we will use a base length (hypotenuse) of 8 meters. Knowing this we can find the length of both sides is ~5.66

45 45 90 side

The next step is to determine the total area of this triangle, and because there is a formula for finding the area of 45 45 90 triangle, all we need to do is plug in our side length.

45 45 90 area

Next we need to determine the height so we can divide it into even layers. To do this, because of the special ratios of this triangle, we'll use the same equation for finding the side length but instead of using the hypotenuse length we'll use the side length.

45 45 90 height

The height of this triangle is ~4 meters, which makes each level ~1.33 meters high. Now with the height and base angle we turn again to the trigonometric function used for the great pyramid to find how base the length of the UI level.

45 45 90 base length

Now we have the base length of the UI level triangle we can plug it into the formula for finding the area of an 45 45 90 triangle

45 45 90 area

The UI level is about 11.1% of the total pyramid. To figure out the remaining levels it's a matter of repeating these steps for the service level and then using the same method of subtracting the triangles as we did for the great pyramid.

Level UI Service Unit
area 1.79 5.32 8.91
% of total 11.17% 33.21% 55.62%

Analyzing Results

Putting the results from all three triangles together, despite the size differences in the sample triangles the results are very uniform.

3 levels UI Service Unit
Great Pyramid 11.1% 33.3% 55.6%
Equilateral 11.1% 33.4% 55.5%
45-45-90 11.17% 33.21% 55.62%

Considering More Layers

Some test pyramids you may find have more than 3 layers. To get a sense of how more layers affects the amount of area UI testing should represent in your testing strategy. The results from using the same mathematical process for 4 and 5 equal layers are below:

4 levels UI Component Integration Unit
Great Pyramid 6.3% 18.7% 31.3% 43.7%
Equilateral 6.3% 18.8% 31.3% 43.7%
45-45-90 6.18% 18.79% 31.15% 43.88%

Since there has consistently been only minor variations between the different triangle types for 5 layers it seems pretty safe to draw conclusions based on the rounded results of the triangle based on the Great Pyramid.

5 levels UI API Component Integration Unit
Great Pyramid 4% 12% 19.8% 28.2% 36%

Uncovering More

Reflecting on these numbers can be insightful, to dig deeper into what mysteries these numbers can reveal check out my article the Mysteries and Mathematics of the Test Pyramid on the Ministry of Testing Dojo.