ExceptionAsserts & debugging your C# project in VS
We've been using NUnit & VisualStudio to write C# .NET code for a while now. Testing Exceptions was done in the style of

<pre>
[ExpectException(typeof(ExceptionType))] 
public void TestExceptionType()
{

}
</pre>

Now NUnit has released version 2.5.2 which introduced `Assert.Throws( Type expectedExceptionType, TestDelegate code );` This makes exception testing a whole lot more flexible. Our exception tests now look like this:

<pre>
[Test]
public void TestWithNullBufferArgument()
{
     Assert.Throws<NullReferenceException>(() => _testInstance.TestFunction(null));
}
</pre>

Our problem is that if Assert.Throws is used Visual Studio will cough up a window showing an unhandled exception when NUnit (either console or GUI runner) is used to debug the program. This stops NUnit from continuing the tests. It is possible to continue debugging/unit testing by pressing F5 but this is not a viable solution.

Is there any way to avoid this? Putting a try...catch block around the Assert.Throws does nothing since the exception happens in the delegate code.

I hope someone can shed some light on this.
ExceptionAsserts & debugging your C# project in VS
===

We've been using NUnit & VisualStudio to write C# .NET code for a while now. Testing Exceptions was done in the style of

<pre>
[ExpectException(typeof(ExceptionType))] 
public void TestExceptionType()
{

}
</pre>

Now NUnit has released version 2.5.2 which introduced `Assert.Throws( Type expectedExceptionType, TestDelegate code );` This makes exception testing a whole lot more flexible. Our exception tests now look like this:

<pre>
[Test]
public void TestWithNullBufferArgument()
{
     Assert.Throws<NullReferenceException>(() => _testInstance.TestFunction(null));
}
</pre>

Our problem is that if Assert.Throws is used Visual Studio will cough up a window showing an unhandled exception when NUnit (either console or GUI runner) is used to debug the program. This stops NUnit from continuing the tests. It is possible to continue debugging/unit testing by pressing F5 but this is not a viable solution.

Is there any way to avoid this? Putting a try...catch block around the Assert.Throws does nothing since the exception happens in the delegate code.

I hope someone can shed some light on this.