Re: Blog: Four Ways to test Expected Exceptions

"Charlie Poole" <[email protected]> Sat, 2 Aug 2008 16:38:23 -0700
Newsgroups gmane.comp.windows.dotnet.nunit.user,gmane.comp.windows.dotnet.nunit.devel
Message-ID <006e01c8f4f8$dd82c220$6401a8c0@ferrari>
Hi David,
 
I think I'm missing something... Why isn't that code equivaent to...
 
Assert.That(  delegate { do_something() }, Throws.Exception<MyException>()
);
 
Charlie


  _____  

From: [email protected]
[mailto:[email protected]] On Behalf Of David Jeske
Sent: Saturday, August 02, 2008 12:01 PM
To: Charlie Poole
Cc: [email protected]; [email protected]
Subject: Re: [Nunit-users] Blog: Four Ways to test Expected Exceptions


I find separating every single exception test into a different methods
inconvinent and unweildy, mostly because of the need to access local
variables. I usually use a codeblock like this sitting in a test function
with lots of other stuff. The block looks like this:

{
  bool err = false;
  try { 
     do_something();
  } catch (MyException) {
     err = true;
  }
  Assert.AreEqual(err,true, "Expected MyException");
}

I'd be happy for a more terse way to write this, but I don't see how to do
it while retaining the ability to access the test-function scope. Passing in
all the necessary arguments is just annoying.


On Fri, Aug 1, 2008 at 5:43 PM, Charlie Poole <[email protected]> wrote:


Hi All,

It's here: http://blogs.nunit.com

Comments?

-------------------------------------------------------------------------
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=/

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users