DEV Community

Discussion on: Code Smell 52 - Fragile Tests

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.