xUnit.Net在测试运行器中调试测试时忽略异常

时间:2014-05-10 19:48:09

标签: .net visual-studio unit-testing debugging xunit.net

在Visual Studio中,我通常保留用于处理异常的默认设置,这会使调试器停止在用户代码中未处理的异常。

XUnit.net中,我使用Assert.Throws<T>进行异常测试:

var exception = Assert.Throws<ArgumentException(() => { TestMethod(); });

static void TestMethod() {
    if (condition)
        throw new ArgumentException("Test Message");
    /// .. more code here
}

当我从测试运行器(ReSharper或NCrunch)运行时,效果很好。

当我从这些环境中的任何一个 Debug 时,我会在An exception of type ... occurred in ... but was not handled in user code的调试器中停止。

只有在我调试单元测试时,是否有一种干净的方法可以消除该消息?

我可以在Visual Studio中设置调试器选项来忽略这些错误,但这不是我喜欢的想法。

我可以滚动我自己的try / catch块,但这似乎就像重新发明了xunit的坏副本。查看源代码,我可以在try / catch块中看到代码,但它显然不是用户&#39;代码就Visual Studio而言(导致它在DLL中)。

我不能成为第一个碰到这个问题的人,但是我们在这里没有看到它,所以我必须犯一个新手的错误。那里有一个很好的解决方案吗?

0 个答案:

没有答案