如何从 Visual Studio 在调试模式下运行 NUnit? [英] How do I run NUnit in debug mode from Visual Studio?

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

问题描述

我最近一直在为我一直在研究的一些 C# 构建一个测试框架.我在我的工作区中设置了 NUnit 和一个新项目来测试组件.如果我从 Nunit (v2.4) 加载我的单元测试,一切都很好,但我已经到了在调试模式下运行并设置一些断点非常有用的地步.

I've recently been building a test framework for a bit of C# I've been working on. I have NUnit set up and a new project within my workspace to test the component. All works well if I load up my unit tests from Nunit (v2.4), but I've got to the point where it would be really useful to run in debug mode and set some break points.

我尝试了几个指南中的建议,它们都建议更改测试项目的调试"属性:

I've tried the suggestions from several guides which all suggest changing the 'Debug' properties of the test project:

Start external program: C:Program FilesNUnit 2.4.8in
unit-console.exe
Command line arguments: /assembly: <full-path-to-solution>TestDSPinDebugTestDSP.dll

我在那里使用控制台版本,但也尝试过调用 GUI.当我尝试开始调试时,两者都给我同样的错误:

I'm using the console version there, but have tried the calling the GUI as well. Both give me the same error when I try and start debugging:

Cannot start test project 'TestDSP' because the project does not contain any tests.

这是因为我通常将 DSP.nunit 加载到 Nunit GUI 中,这就是进行测试的地方吗?

Is this because I normally load DSP.nunit into the Nunit GUI and that's where the tests are held?

我开始认为问题可能在于 VS 想要运行它自己的测试框架,这就是它找不到 NUnit 测试的原因?

I'm beginning to think the problem may be that VS wants to run it's own test framework and that's why it's failing to find the NUnit tests?

编辑:对于那些询问测试装置的人,我在 TestDSP 项目中的一个 .cs 文件大致如下所示:

Edit: To those asking about test fixtures, one of my .cs files in the TestDSP project looks roughly like this:

namespace Some.TestNamespace
{
    // Testing framework includes
    using NUnit.Framework;

    [TestFixture]
    public class FirFilterTest
    {
        [Test]
        public void Test01_ConstructorTest()
        {
            ...some tests...
        }
    }
}

...我对 C# 和 NUnit 测试框架还很陌生,所以我完全有可能错过了一些关键信息;-)

...I'm pretty new to C# and the NUnit test framework so it's entirely possible I've missed some crucial bit of information ;-)

最终解决方案:最大的问题是我使用的项目.如果您选择 Other Languages ->Visual C# ->测试 ->测试项目 ...当您选择项目类型时,Visual Studio 将尝试使用它自己的测试框架,据我所知.您应该选择一个普通 C# 类库项目,然后我选择的答案中的说明将起作用.

Final Solution: The big problem was the project I'd used. If you pick Other Languages -> Visual C# -> Test -> Test Project ...when you're choosing the project type, Visual Studio will try and use it's own testing framework as far as I can tell. You should pick a normal C# class library project instead and then the instructions in my selected answer will work.

推荐答案

我使用与您尝试 Jon 相同的技术,没有/assembly 标志,即

I use the same technique as you are trying Jon, without the /assembly flag, i.e.

Start External Program: C:Program FilesNUnit 2.4.8in
unit.exe

Command line arguments: "<path>inDebugQuotes.Domain.Tests.dll"

TestDSP.dll 是否包含您所有的 TestFixtures?

Does TestDSP.dll contain all your TestFixtures?

由于我的测试项目不是解决方案中的启动项目,我通过右键单击测试项目并选择调试 --> 启动新实例来运行我的测试

As my test project is not the startup project in the solution, I run my tests by right-clicking on the test project and choosing Debug --> Start New Instance

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

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