在 Visual Studio C# Express 2010 中调试 Nunit 测试
我遵循这个建议来调试 NUnit 测试。
http://www.blackwasp.co.uk/NUnitCSharpExpress.aspx
但是,我有几个执行 Assert.Throws<...>
的测试,这会导致调试器在我正在测试的异常发生时中断,而实际上我希望它在异常发生在外部时中断那些电话。
如何让调试器忽略这些方法中引起的异常?
编辑:我已经尝试过以下方法,但不起作用!
[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
{
}
}
I've followed this advice to get debugging working for NUnit tests.
http://www.blackwasp.co.uk/NUnitCSharpExpress.aspx
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?
EDIT: 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
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是对我有用的(虽然在 Visual Studio Professional 中,而不是 Express,但我想这应该不重要)。
按照 Ninjapig 的建议调出“例外”对话框。
点击
Add...
按钮,打开“New Exception”对话框。确定
关闭“新建异常”对话框。Thrown
和User-unhandled
)均未选中。现在,调试器应该完全忽略 NUnit 断言失败(即抛出、捕获或未捕获,
NUnit.Framework.AssertionException
)。UPDATE:这只会阻止闯入调试器,它不能忽略异常本身;即它不会改变实际的程序流程。除了更改、替换或封装 try-catch 块中的断言调用之外,我认为没有任何方法可以实现这一目标(至少不能自动实现)。
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.OK
to close the "New Exception" dialog.Thrown
andUser-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).
我不确定 VS2010 Express 是否有此选项,但您可以选择要中断的例外。
转到“调试”菜单,然后选择“异常”
从这里您可以选择要中断的异常
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
我最终引用了 nunit-gui-runner.dll 并像这样调用它,
这会调出 NUnit gui。然后我可以运行我感兴趣的特定测试。
I've ended up referencing
nunit-gui-runner.dll
and invoking it likeThis brings up the NUnit gui. I can then run the specific test i'm interested in.
我也有同样的问题。尽管您的原始方法(不需要
try...catch
块)适用于大多数异常类型,但ArgumentNullException
不起作用。我这样修复它:它不是那么优雅,但它似乎确实有效。
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:It's not as elegant, but it does seem to work.