Welcome to

Magenic Technologies Community Blog

Sign in | Join | Help

NUnit testing in WCF - ExpectedException<T>

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.

Published Monday, March 19, 2007 4:43 PM by jeffk
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required)