Four Pillars of a Good Test (Khorikov)

In his book “Unit Testing Principles, Practices and Patterns”, Vladimir Khorikov outlines four pillars of unit test design. This learning hour introduces them.


Connect - web hunt test design principles

What test design principles do you know already?

For example people might talk about the test pyramid, or white box testing, or “don’t mock what you don’t own”.

Concept - Four pillars of a good test

Vladimir Khorikov describes these pillars of a good test in his book “Unit Testing Principles, Practices and Patterns”:

Explain them.

Concrete - examine sample tests

Have them review the example test cases for MessageRenderer. For each one, which pillar(s) are in trouble?

Concrete - write tests for WordWrap

One of the pillars is “Resistance to refactoring”. That means the design of the code could change without the test needing to change. Take a look at WordWrap-TestDesign-Kata. In this exercise there are several designs for the same functionality. Write some test cases that work for any of the implementations. Aim to cover all the interesting functionality and edge cases.

Evaluate your tests against all the four pillars. In particular, “Resistance to refactoring”. What is it about this code that makes it easy to score well on that pillar?

Conclusions - how about your test code?

In your team, which of these test design pillars do you have the most trouble with? Discuss in pairs. Look for examples in your sourcecode that are particularly bad.