调试NUnit的测试在Visual Studio C#2010速成 [英] Debugging Nunit tests in Visual Studio C# Express 2010

查看:205
本文介绍了调试NUnit的测试在Visual Studio C#2010速成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遵循了这一建议得到的调试NUnit的测试工作。



http://www.blackwasp.co.uk/NUnitCSharpExpress.aspx



不过,我有几个测试,做 Assert.Throws< ...> ,这将导致调试器打破时,我测试了发生异常的时候,确实我想如果发生这些呼叫之外的例外,它打破



我怎样才能调试器忽略这些种方法内引起的异常?






编辑:!我已经试过事件下面,它不工作

  [测试] 
公共无效InstanciatingWithNullParameterThrowsException()
{

{
Assert.Throws< ArgumentNullException>(()=>新建CachedStreamingEnumerable< INT>(空) );
//这仍然抛出和止损是能够经过这一个
称为}

{

}
}调试测试


解决方案

下面是我在Visual Studio什么工作(虽然专业的,不会表达,但我想这不应该的问题)。




  • 弹出例外对话框通过Ninjapig的建议


  • 点击添加... 按钮,打开新建例外对话框。


  • 在下拉框中

  • 在编辑框中选择公共语言运行库异常中输入NUnit.Framework.AssertionException

  • 点击确定关闭新建例外对话框。

  • 早在例外对话框中确保两个复选框(时抛出用户未处理)是的选中



现在,调试器应该完全忽略一个NUnit的断言失败(即抛出,捕获与否, NUnit.Framework.AssertionException )。



更新:这只能从打破进入调试器阻止,也不能忽视例外本身;即,它不会改变实际的程序流程。 APPART更改或替换或封装中的try-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
    {

    }
}

解决方案

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.

  • Select "Common Language Runtime Exceptions" in the drop down box
  • In the Edit box enter "NUnit.Framework.AssertionException".
  • Click OK to close the "New Exception" dialog.
  • Back in the "Exceptions" dialog make sure that both checkboxes (Thrown and User-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).

这篇关于调试NUnit的测试在Visual Studio C#2010速成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆