[英]Debugging Nunit tests in Visual Studio C# Express 2010
我已经按照这个建议来调试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
{
}
}
这对我有用(虽然在Visual Studio Professional中,不是Express,但我想这应该不重要)。
按照Ninjapig的建议提出“例外”对话框。
单击Add...
按钮,打开“New Exception”对话框。
OK
”关闭“新例外”对话框。 Thrown
和 User-unhandled
)。 现在,调试器应该完全忽略NUnit断言失败(即抛出,捕获或未捕获, NUnit.Framework.AssertionException
)。
更新 :这只会阻止进入调试器,它不能忽略异常本身; 即它不会改变实际的程序流程。 在更改或替换或封装try-catch块中的Assert-calls时,我认为没有任何东西可以实现(至少不会自动)。
我不确定VS2010 Express是否有此选项,但您可以选择中断例外。
转到“调试”菜单,然后选择“例外”
从这里你可以选择要打破的例外情况
我最终引用了nunit-gui-runner.dll
并调用它
NUnit.Gui.AppEntry.Main(new string[] { Dll });
这带来了NUnit gui。 然后我可以运行我感兴趣的特定测试。
我有同样的问题。 虽然您的原始方法(不需要try...catch
块)适用于大多数异常类型,但ArgumentNullException
不起作用。 我这样修好了:
[Test]
public void InstanciatingWithNullParameterThrowsException()
{
bool isArgumentNullExceptionThrown = false;
try
{
new CachedStreamingEnumerable<int>(null);
}
catch (ArgumentNullException)
{
isArgumentNullExceptionThrown = true;
}
Assert.That(isArgumentNullExceptionThrown);
}
它并不优雅,但似乎确实有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.