Re: Testing for errors

"Seyit Caglar Abbasoglu" <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
Another idea that comes to my mind is to use reflection to delay method
invocation. You can create a general IsError method works like:

[Test]
public void at_errorIfIndexOutOfRange()
{
  Vector vector = new Vector();
  Assert.IsError (vector, "at", -1);
}

with the method on Assert class:

public void IsError (object methodOwner, string methodName, params object[]
paremeters)
{
  try
  {
     BindingFlags flags = BindingFlags.InvokeMethod | BindingFlags.Instance|
BindingFlags.Public;

     Type ownerType = methodOwner.GetType ();
     ownerType.InvokeMember (methodName, flags, null, methodOwner,
paremeters);
  }
  catch (TargetInvocationException)
  {
    return;
  }

  Assert.Fail("There should be an error on method call {0}.{1}",
methodOwner, methodName);
}

And you can create a more clever method (perhaps generic) who expects a
specific exception. Although being an option, I would prefer
ExpectedException attribute rather than using reflection. Actually I hate
reflection and use it only when it's absolutely necessary.

Note: By the way I realized that direct reply to a mail sends to the
original poster not to the group. This was not the way I'm familiar with in
yahoo-groups. I apologize for previous personal mails.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.