NUnit testing in WCF - ExpectedException

by jk 19. March 2007 16:43

One thing I noticed while testing a WCF service endpoint via NUnit (v 2.2.8) is that if you mark a test with the ExpectedException attribute like this:

[Test]
[ExpectedException(typeof(FaultException))]
public void MyFancyWCFTest()
{
   //some high-powered testing code here which is expecting an exception; e.g. testing incoming message validation
}
 
the NUnit framework will call this a failure because the FaultException uses a generic type, e.g. ExceptionDetail...

[Test]
[ExpectedException(typeof(FaultException<ExceptionDetail>))]
public void MyFancyWCFTest()
{
   //some high-powered testing code here which is expecting an exception; e.g. testing incoming message validation
}

Hopefully this simple post will save someone time and/or a headache :)

cheers

jk

Edit:  6/17/2007 -- And as Jason correctly pointed out, you need to have includeExceptionDetailInFaults=True for this to work.  I was in development during this post and had not considered this point.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen