DEV Community

Cover image for Code Smell 52 - Fragile Tests

Code Smell 52 - Fragile Tests

mcsee profile image Maxi Contieri ・1 min read

Tests are our safety nets. If we don't trust on their integrity we will be in great danger.


  • Determinism

  • Confidence loss

  • Wasted time


  1. Test should be in full control. There should be no space for erratic behavior and degrees of freedom.

  2. Remove all tests coupling.


  • Fragile, Intermittent, Sporadic or Erratic tests are common in many organizations.

Nevertheless, they mine the developers trust.

We must avoid them.

Sample Code




Detection can be done with test run statistics.

It is very hard to put some test in maintenance since we are removing a safety net.

More Info


  • Coupling

  • Determinism


Fragile tests show system coupling and not deterministic or erratic behavior.

Developers spend lots of time and effort fighting against this false positives.


Photo by Jilbert Ebrahimi on Unsplash

The amateur software engineer is always in search of magic.

Grady Booch

Discussion (1)

Editor guide
yoursunny profile image
Junxiao Shi

Should tests verify the internals (private fields) of a class?
I've seen many test cases that assert every internal variable. I don't like that.

My reason is: Every time you refactor the class you have to rewrite the tests. However, tests are supposed to ensure the external behaviour of a class doesn't change unexpectedly. If the tests are rewritten, it's hard to confirm whether the external behaviour changed.