How can unit testing make parameter validation redundant?

Posted by Johann Gerell on Stack Overflow See other posts from Stack Overflow or by Johann Gerell
Published on 2012-06-24T21:04:10Z Indexed on 2012/06/24 21:16 UTC
Read the original article Hit count: 158

Filed under:
|
|

We have a convention to validate all parameters of constructors and public functions/methods. For mandatory parameters of reference type, we mainly check for non-null and that's the chief validation in constructors, where we set up mandatory dependencies of the type.

The number one reason why we do this is to catch that error early and not get a null reference exception a few hours down the line without knowing where or when the faulty parameter was introduced. As we start transitioning to more and more TDD, some team members feel the validation is redundant.

Uncle Bob, who is a vocal advocate of TDD, strongly advices against doing parameter validation. His main argument seems to be "I have a suite of unit tests that makes sure everything works".

But I can for the life of it just not see in what way unit tests can prevent our developers from calling these methods with bad parameters in production code.

Please, unit testers out there, if you could explain this to me in a rational way with concrete examples, I'd be more than happy to seize this parameter validation!

© Stack Overflow or respective owner

Related posts about c#

Related posts about c++