Debugging Nunit tests in Visual Studio C# Express 2010

南楼画角 提交于 2019-12-05 06:16:57

Here is what worked for me (although in Visual Studio Professional, not Express, but I guess that should not matter).

  • Bring up the "Exceptions" Dialog as suggested by Ninjapig.

  • Click on the Add... Button, to open the "New Exception" dialog.

  • Select "Common Language Runtime Exceptions" in the drop down box
  • In the Edit box enter "NUnit.Framework.AssertionException".
  • Click OK to close the "New Exception" dialog.
  • Back in the "Exceptions" dialog make sure that both checkboxes (Thrown and User-unhandled) are unchecked.

Now, the debugger should completely ignore a NUnit assertion failure (i.e. a thrown, caught or not, NUnit.Framework.AssertionException).

UPDATE: This will only prevent from breaking into the debugger, it cannot ignore the exception itself; i.e. it will not alter the actual program flow. Appart from changing or replacing or encapsulating the Assert-calls in try-catch blocks, I don't think there is anything that can achieve that (at least not automatically).

I'm uncertain if VS2010 Express has this option, but you can choose the exceptions to break on .

Go to the 'Debug' menu, then select 'Exceptions'

and from here you can select what exceptions to break on

I've ended up referencing nunit-gui-runner.dll and invoking it like

NUnit.Gui.AppEntry.Main(new string[] { Dll });

This brings up the NUnit gui. I can then run the specific test i'm interested in.

I had the same problem. Although your original approach (without the need for a try...catch block) works for most exception types, ArgumentNullException doesn't work. I fixed it like this:

[Test]
public void InstanciatingWithNullParameterThrowsException()
{
    bool isArgumentNullExceptionThrown = false;
    try
    {
       new CachedStreamingEnumerable<int>(null);
    }
    catch (ArgumentNullException)
    {
        isArgumentNullExceptionThrown = true;
    }
    Assert.That(isArgumentNullExceptionThrown);
}

It's not as elegant, but it does seem to work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!