Mathieu Eveillard

50 shades of tests

50 shades of tests

I’ve been wanting to write this essay on testing for a while now. Well, I say “essay,” but it’s really more of a survey. The value I hope to provide through this article is based on categorizing tests into three parts: purpose, granularity, and type of assertion.

Let’s start with an example: I’m often asked how acceptance tests fit into the testing pyramid. My answer is “almost everywhere,” because different types of tests can fulfill this role, from unit tests to end-to-end tests. This means that not all tests are comparable, nor are they mutually exclusive, so we must consider their various facets. We’ll call these facets “dimensions.”

These dimensions (purpose / granularity / type of assertion) are nearly independent:

Of course, it all comes down to the “almost,” since there are counterexamples. Nevertheless, I still find this classification useful.

Let’s get started, follow the guide!

Dimension: Purpose

This is, of course, where we must begin: not all tests have the same purpose. Some aim to validate the design, others the development, and still others to prevent regressions, etc. Let’s look at this in detail:

Dimension: granularity

This is the dimension most often discussed in connection with the concept of the test pyramid. This concept is essential because it encourages us to use the full spectrum of testing methods with the goal of testing efficiently. The underlying question is: “How can I achieve maximum reliability by writing as few tests as possible?”

Dimension: type of assertion

The final dimension is the type of assertion. In other words, “what am I testing?” and therefore, “what level of assurance does this type of test provide?”

Conclusion

One final note: all tests can and should be automated and run on the CI as much as possible, with the exception of user tests and exploratory tests, for which this would not make sense. There are two reasons for this:

Next, knowing which tests to use requires a bit of experience and a lot of pragmatism. The key is to avoid falling into the “tool-centric” trap, that is, thinking, “I only know one type of test, so that’s all I do.” Your application won’t fare well if it relies solely on unit tests. Nor will it fare any better if it relies solely on end-to-end tests.

(*) Scott Wlaschin illustrates this very well with the following image: “Unit tests have been compared with shining a flashlight into a dark room in search of a monster. Shine the light into the room and then into all the scary corners. It doesn’t mean the room is monster-free—just that the monster isn’t standing where you’ve shined your flashlight.”

← All posts