在Visual Studio C#Express 2010中调试Nunit测试

在Visual Studio C#Express 2010中调试Nunit测试

问题描述:

我已经按照这个建议来调试工作用于NUnit测试。

I've followed this advice to get debugging working for NUnit tests.

http://www.blackwasp.co.uk/NUnitCSharpExpress.aspx

但是,我有几个测试执行 Assert.Throws< ...> ,这会导致调试器在异常测试发生时中断,当我真的想要破解如果异常发生在这些电话之外。

However, i have several tests that do Assert.Throws<...>, which causes the debugger to break when the exception i'm testing for occurs, when really i want it to break if an exception occurs outside of those calls.

如何让调试器忽略由这些方法引起的异常?

How can i get the debugger to ignore exceptions caused from within these kinds of methods?

编辑:我尝试了以下事件,这不起作用。

I've event tried the below, which doesn't work!

[Test]
public void InstanciatingWithNullParameterThrowsException()
{
    try
    {
        Assert.Throws<ArgumentNullException>(() => new CachedStreamingEnumerable<int>(null));
        // This still throws and stops be being able to debug tests called after this one
    }
    catch
    {

    }
}


这是对我有用的(虽然在Visual Studio专业,不是快递,但是我猜这不要紧。)

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


  • 根据Ninjapig的建议,引发异常对话框

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

点击 Add ... 按钮,打开新建异常对话框。

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

应该完全忽略NUnit断言失败(即抛出,被捕获或不被捕获, NUnit.Framework.AssertionException )。

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

UPDATE :这只会阻止进入调试器,它不能忽略本身的异常;即不会改变实际的程序流程。通过在try-catch块中更改或替换或封装Assert调用,我不认为有什么可以实现的(至少不是自动的)。

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).