小编Wad*_*ler的帖子

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
}
Run Code Online (Sandbox Code Playgroud)

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

但是,当我从这两种环境中的任何一个进行调试时,我都会在调试器中使用An exception of type ... occurred in ... but was not handled in user code.

只有在我调试单元测试时,是否有一种干净的方法才能使该消息消失?

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

我可以推出自己的 try/catch 块,但这似乎就像重新发明了一个糟糕的 xunit 副本。望着源,我可以看到,该代码在一个try / catch块,但它显然不是只要Visual Studio是有关“用户”的代码(因为它是在DLL)。

我不可能是第一个遇到这个问题的人,但还没有看到这里讨论过,所以我一定是在犯一个新手错误。有什么好的解决办法吗?

.net debugging unit-testing xunit.net visual-studio

5
推荐指数
0
解决办法
853
查看次数

标签 统计

.net ×1

debugging ×1

unit-testing ×1

visual-studio ×1

xunit.net ×1