如何调试在Visual Studio 2010 NUnit测试 [英] How to debug Nunit test in Visual Studio 2010

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

问题描述

我有调试的VisualStudio从一个NUnit测试的一个问题。我创建了一个空项目(控制台应用程序),然后我加入到NUnit的库引用,并写了一个简单的测试。

I have a problem debugging an NUnit test from VisualStudio. I created an empty project (Console Application), then I added references to the NUnit library and wrote a simple test.

namespace ReimplementingLinq.Tests
{
    [TestFixture]
    public class WhereTest
    {
        [Test]
        public void SimpleFiltering()
        {
            int[] source = { 1, 2, 3, 4, 2, 8, 1 };
            var result = source.Where(val => val < 4);
            int[] expected = {1,2,3,4};
            CollectionAssert.AreEqual(expected, result);
        }
    }
}



接下来,我跟着给出的建议在这个环节
我如何在从Visual Studio调试模式下运行NUnit的?但没有在我的专题工作方案。在执行测试我的断点没有被击中。我试图通过连接到处理和也通过运行与参数的外部程序的项目测试溶液。

Next I followed the advice given in this link How do I run NUnit in debug mode from Visual Studio? but none of the solutions in that topic work for me. None of my breakpoints are hit while performing the test. I tried testing the solution by attaching to the process and also by running the project with an external program with arguments.

我能做些什么来调试我的单元测试?

What can I do to debug my unit test?

推荐答案

假设你正在使用的不是速成版,然后 TestDriven.NET 可能会使用。

Assuming you're using a version of Visual Studio other than Express Edition then TestDriven.NET might be of use.

在安装后,它


  1. 设置您的测试方法中的一个断点

  2. 从一测试单击并选择调试器由于菜单

  3. 调试器应启动并打你的断点

不幸的是你不能因为TestDriven.NET是Visual Studio的一个插件和Express版本不支持使用插件

Unfortunately you can't use this method with Express editions of visual studio because TestDriven.NET is a plugin for visual studio and the Express editions do not support the use of plugins

您也可以运行通过一个控制台应用程序在调试器测试:

You can also run a test in the debugger via a console application:


  1. 创建一个新的控制台应用程序

  2. 引用的单元测试项目

  3. 里面的主要方法控制台应用程序创建测试fixuture的新实例,然后调用的测试方法之一。例如,如果我有一个名为夹具和MyTests名为Test1的测试中,我会写:

  1. Create a new console application
  2. Reference your unit tests project
  3. Inside the Main method of the console application create a new instance of your test fixuture and then call one of the test methods. For example if I have a fixture named MyTests and a test named Test1 I'd write:

var myTests = new MyTests();
myTests.Test1();


  • 将在该行设置一个断点,你创建 MyTests 类,并按F5

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

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