[英]Debugging Nunit tests in Visual Studio C# Express 2010
I've followed this advice to get debugging working for NUnit tests. 我已经按照这个建议来调试NUnit测试。
http://www.blackwasp.co.uk/NUnitCSharpExpress.aspx 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. 但是,我有几个测试做Assert.Throws<...>
,这导致调试器在我正在测试的异常发生时中断,当我真的希望它在这些调用之外发生异常时中断。
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
{
}
}
Here is what worked for me (although in Visual Studio Professional, not Express, but I guess that should not matter). 这对我有用(虽然在Visual Studio Professional中,不是Express,但我想这应该不重要)。
Bring up the "Exceptions" Dialog as suggested by Ninjapig. 按照Ninjapig的建议提出“例外”对话框。
Click on the Add...
Button, to open the "New Exception" dialog. 单击Add...
按钮,打开“New Exception”对话框。
OK
to close the "New Exception" dialog. 单击“ OK
”关闭“新例外”对话框。 Thrown
and User-unhandled
) are unchecked . 返回“异常”对话框,确保取消选中两个复选框( Thrown
和 User-unhandled
)。 Now, the debugger should completely ignore a NUnit assertion failure (ie a thrown, caught or not, NUnit.Framework.AssertionException
). 现在,调试器应该完全忽略NUnit断言失败(即抛出,捕获或未捕获, NUnit.Framework.AssertionException
)。
UPDATE : This will only prevent from breaking into the debugger, it cannot ignore the exception itself; 更新 :这只会阻止进入调试器,它不能忽略异常本身; ie 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). 在更改或替换或封装try-catch块中的Assert-calls时,我认为没有任何东西可以实现(至少不会自动)。
I'm uncertain if VS2010 Express has this option, but you can choose the exceptions to break on . 我不确定VS2010 Express是否有此选项,但您可以选择中断例外。
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-runner.dll
并调用它
NUnit.Gui.AppEntry.Main(new string[] { Dll });
This brings up the NUnit gui. 这带来了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. 虽然您的原始方法(不需要try...catch
块)适用于大多数异常类型,但ArgumentNullException
不起作用。 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. 它并不优雅,但似乎确实有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.