Re: Blog: Four Ways to test Expected Exceptions
"Charlie Poole" <[email protected]> Sat, 2 Aug 2008 10:26:01 -0700
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <005201c8f4c4$d616e090$6401a8c0@ferrari> |
Hi Brad,
> I haven't had occasion to use this method of testing
> exceptions (though to be fair, I can't remember the last time
> I used *any* method for testing exceptions), but your
> explanation is clear, and its use seems much clearer and more
> precise than the previous method. I'd much rather use the
> new than the old, but that's true for other assertions, too.
I was dubious about inline checking of exceptions back when
.NET 1.0 and 1.1 were the more used framework versions. Having
to use a separate method and instantiate a delegate for each
test made it just too difficult. But with 2.0 it got easier
and 3.0/3.5 made it easier still. NUnit actually supports
versions of this Assert/Constraint that work in .NET 1.0 and 1.1,
but I don't think I would use them myself - except for testing
them within NUnit that is.
> After some initial apathy ("skepticism" is really too strong
> to describe what I felt), I've pretty much started using the
> constraint methods exclusively over the Assert syntax,
> sometimes even changing old test code when I need to change
> what it's testing. It just makes my code so much easier to
> read and parse. One other developer on my team, for whom
> "skepticism" wasn't strong *enough*, has also switched after
> really looking at the resulting test code, and output. :)
That's good to hear. The irony is that I was quite skeptical
about such "fluent interfaces" myself but I finally figured that
I had to try it, which meant I had to write it. I'm
now convinced as well. :-)
Charlie
> Brad
>
>
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/