DEV Community

Cover image for Code Smell 52 - Fragile Tests

Code Smell 52 - Fragile Tests

Maxi Contieri on January 04, 2021

Tests are our safety nets. If we don't trust on their integrity, we will be in great danger. TL;DR: Don't write non-deterministic tests. ...
Collapse
 
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.