Published August 27, 2020
by Doug Klugh

Quality Engineering

Avoid this code smell by writing tests from Simple Designs and refactor as needed to keep your test code clean.  Good tests are understood at a glance and clarify the behavior they verify.  Structure Matters as much for tests as it does production code.  Apply design principles and patterns to enhance the structural quality of tests — as they are every bit as important as production code and should be given the same amount of attention.  Behavioral quality can also be enhanced to ensure correctness of the tests by inhibiting errors from hiding within obscure code.

Cause & Effect

While the following patterns lead to Obscure Tests, the general root cause is having the wrong information within the tests.

Eager Testlaunch

This code smell occurs when we try to minimize the number of tests we need to write and end up verifying too many test conditions. 

Mystery Guest

This code smell occurs when a test depends on mysterious external resources, of which the purpose is not well understood.  This makes it difficult to understand the relationship between the test fixture and the expected behavior of the test.

General Fixture

This is caused when a test relies on a fixture that is larger than needed to verify the SUT.

Irrelevant Information

This occurs when a test reveals irrelevant details that distracts the developer from understanding what really affects the behavior of the SUT.

Indirect Testing

This occurs when a test interacts with the SUT indirectly through another object which leads to complex interactions.