Recently somebody mentioned to me that they don’t really like the test pyramid, and prefer the swiss cheese model.
So I looked it up (again), and thought “yeah, that’s nice”. And you know how it sometimes goes, it kept niggling away at the back of my brain – now there’s a mental image you didn’t need today! I’ve linked a few resources to learn more at the end of the blog. 👇🏻
Anyhow, something wasn’t sitting right with me, but I had a very challenging and busy week, and no time to actually THINK about what was causing my slight mental discomfort.
Until today, when somebody mentioned it again, in a comment about the Crowdstrike issue, and finally it clicked. My mental dissonance was caused by the fact that I keep hearing about the Swiss Cheese Model as a replacement for the Test Pyramid, and that’s not how I see it.
The pyramid model is deceptive simple, because that’s what good models do: they visualise more complex ideas in an easy to comprehend way.
The test pyramid describes how types of test should be distributed:
- mostly easy to write and maintain unit tests
- a lesser amount of the slightly more complex component tests
- even fewer integration tests
- only the most necessary full system or end-to-end tests
So far, so good.
Every once in a while someone feels it needs redefining or updating, and there’s nothing wrong with that desire, of course. The pyramid model is deceptive simple, because that’s what good models do: they visualise more complex ideas in an easy to comprehend way.
Is this a 100% accurate description for every system under test? Of course not. And are there unaccounted complexities when considering cloud-hosted systems or microservice architectures? Absolutely. However, it provides a useful guideline for test distribution: Write many easy tests and avoid writing many expensive and difficult tests. Got it.
Now, the swiss cheese model does away with all of that and focusses on the layers that target different areas of your tech stack.
The new kid on the block (not so new, actually)
Wikipedia explains it like this: ”The Swiss cheese model of accident causation is a model used in risk analysis and risk management. It likens human systems to multiple slices of Swiss cheese, which has randomly placed and sized holes in each slice, stacked side by side, in which the risk of a threat becoming a reality is mitigated by the differing layers and types of defenses which are “layered” behind each other. Therefore, in theory, lapses and weaknesses in one defense do not allow a risk to materialize (e.g. a hole in each slice in the stack aligning with holes in all other slices), since other defenses also exist (e.g. other slices of cheese), to prevent a single point of failure.”
And I love it! This is something I’m a huge proponent of, the removal of single points of failure as well as letting a thorough analysis of risk guide our testing efforts.
The problem with replacing the test pyramid with this model is that it doesn’t provide any guidance on test distribution. Without proper understanding, one might mistakenly believe that all layers should be roughly the same size and thickness (like slices of cheese) to prevent bugs from slipping through. However, this approach is impractical and could easily lead to unnecessary duplication in software testing.
I think it’s a great addition to the pyramid, and I certainly love that it stresses the importance of examining where the “holes” are, the areas of your application where defects can easily slip through.
Conclusion
In conclusion, while the Swiss Cheese Model explains risk management and helps identify potential vulnerabilities in your tech stack, it shouldn’t replace the Test Pyramid. The Test Pyramid provides a clear and practical guideline for test distribution, making sure that we focus our efforts on writing numerous easy-to-maintain unit tests, a moderate number of component tests, fewer integration tests, and only the most essential end-to-end tests.
The beauty of the Swiss Cheese Model lies in its emphasis on layering defences to mitigate risks and avoid single points of failure. This concept is incredibly valuable and complements the Test Pyramid well. By integrating both models, we can create a robust testing strategy that not only prioritises test distribution but also addresses potential vulnerabilities through thorough risk analysis.
So, while the Swiss Cheese Model is an excellent addition to our toolkit, let’s keep the Test Pyramid around, too. Together, they can guide our testing efforts to be both effective and efficient, ensuring we build resilient and high-quality software.
Thanks for reading, and happy testing!
Additional resources
The Swiss Cheese Model for Quality Engineering, Imran Qureshi
Pingback: Risk-Based Testing in Agile and DevOps Teams - Kato Coaching
Pingback: Why Are You Asking Me to Test? | Cassandra HL
Comments are closed.