Unit Testing Validators in C#
arphox.github.io
arphox.github.io
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.
var value=10
assert(value, 10)
Would be such a test. Totally useless. Just duplication of logic.