Re: Unit tests and parameter validation
Eb <[email protected]>
| Newsgroups | gmane.comp.programming.test-driven-development |
|---|---|
| Message-ID | <CANEY99ZidohT0BT0OVx7MOjPoiPijZrjUy7u2+a+R-=PVO_8=A@mail.gmail.com> |
Thanks for your responses. Colin - what if another developer would be using it (and not the originally creator). How does he/she know that passing in null (for example) is wrong? On Tue, Oct 15, 2013 at 12:52 PM, Colin Vipurs <[email protected]> wrote: > ** > > > 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 <[email protected]> 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: http://eikonne.wordpress.com >> 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. > > > -- blog: http://eikonne.wordpress.com twitter: @eikonne