10 ms·
I don’t see any benefit in testing simple validation rules. Just properly review your rules, and focus on useful tests.
by andix 5y ago
I don’t see any benefit in testing simple validation rules. Just properly review your rules, and focus on useful tests.
- langosvoid 5y agoThere is a debate around what should be tested and what shouldn't. I believe a good developer will try the code they wrote. If you try that out by running your app and e.g. manually forging a request to see it works, good. But in similar time, you could have finished a unit test for it which also shows that it works, but can be repeated anytime. Also we don't just write unit tests to prove our code works, but for many other reasons, e.g.: - they may live as a living documentation of the expectations from the code - they protect against accidental change of logic For a really simple rule, you may say that it is straightforward, but you cannot guarantee that rule _will_ stay simple, and in that case the original feature you just wrote can go bad, maybe unnoticed because there weren't unit tests for it. Good unit tests give confidence to refactor, which is essential for maintainable code.
- andix 5y agoSure. But declaring a validator to be a „unit“ seems a bit too fine grained. I think we agree you shouldn’t test everything. var value=10 assert(value, 10) Would be such a test. Totally useless. Just duplication of logic.