Hacker News new | ask | show | jobs
by Tomis02 2260 days ago
Unit tests are code, and all code has a cost. Writing unit tests without any benefit is harmful behaviour. Real world example: testing dumb getters/setters.
2 comments

That's why I write large sweeping tests that make coverage metric to up, but don't take too much time to write or maintain /s
Writing getters and setters is harmf... - okay, I will stop before things escalate in here!
If you live in OOP land and have a natural aversion to directly accessing the data then by all means, write all the getters and setters you want. But testing that "int getX() { return X;}" actually returns X is pathological behaviour. It's harmful because 1) it costs to write 2) it costs to read 3) it takes up space, distracting from more important tests 4) it costs to run 5) prevents you from easily making changes (it's a brittle test). Can't really see any benefits; if you manage to screw up writing a dumb getter, how do you trust yourself that the test code isn't wrong as well?