¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: [TDD] Unit tests and parameter validation


 

If this is internal code only and the code calling it is also testing then I not only would I not test it but I'd remove all defensive code guards as well. ?For example, a typical pattern would be:

public void foo(SomeObject bar) {
? ?if (bar == null) {
? ?.....
? ?}
}

Instead of catching the null and handling it, ensure all code calling it will never pass in null. ?Cuts down on both test and production code.


On Tue, Oct 15, 2013 at 5:03 PM, Eb <amaeze@...> wrote:
?

Hello everyone -

I'm curious to know thoughts on writing tests that specify the behavior of a method when its inputs are incorrect. ?Is this a common practice. ?How about parameter validation in this case? ?Having some healthy debate on it and wanted to get other insight.

The context for this in a class/methods that are used within an internal application - this is not an API that will be publicly exposed to external consumers.

Thanks.

--
blog:
twitter: @eikonne




--
Maybe she awoke to see the roommate's boyfriend swinging from the chandelier wearing a boar's head.

Something which you, I, and everyone else would call "Tuesday", of course.

Join [email protected] to automatically receive all group messages.