【问题标题】:Visual Studio 2013/2015 Test Project Template - for NUnit?Visual Studio 2013/2015 测试项目模板 - 用于 NUnit?
【发布时间】:2015-10-16 11:00:28
【问题描述】:

我是单元测试新手,从 MSTest 开始,想使用 NUnit。我看到 VS 2015 中有一个测试项目模板,但我读到 NUnit 我要创建一个类库,然后添加 NUnit NuGet 包。

什么是正确的?在 C# 中测试 NUnit 的项目模板或类库?

谢谢

【问题讨论】:

    标签: c# unit-testing nunit visual-studio-2015 project-template


    【解决方案1】:

    Visual Stusio 中没有现成的 NUnit 测试项目模板。

    测试项目是一个引用了 NUnit 安装附带的 nunit.framework.dll 的类库。

    您可以在 Visual Studio 中创建自己的 NUnit 项目模板:

    1. 创建一个新的类库
    2. 参考 nunit.framework.dll
    3. 创建 test.cs 文件
      • 添加“使用 NUnit.Framework;”
      • 创建一个空的测试类和一个测试方法(你也可以在测试类中添加setup和teardown)

    您的 Test.cs 文件应如下所示:

    using System;
    using NUnit.Framework;
    
    namespace NUnit.Tests
    {
      [TestFixture]
      public class SuccessTests
      {
        [SetUp] public void Init()
        { /* ... */ }
    
        [TearDown] public void Dispose()
        { /* ... */ }
    
        [Test] public void Test1()
        { /* ... */ }
      }
    }
    
    1. 使用Export Template wizard 从您的项目中创建模板。

    【讨论】:

      【解决方案2】:

      测试项目设置了一个项目,您可以在其中从 Visual Studio 中进行测试。 NUnit 测试是在外部完成的。它们是不同的选项,每个选项都有不同的要求。

      如果您想按照 NUnit 说明进行 NUnit,请创建一个类库,然后添加 NUnit 包。

      【讨论】:

        【解决方案3】:

        在 VS 2015 中,您拥有 Create Unit Test 功能,右键单击您的方法并选择测试框架。如果为此安装NUnit extension,它将创建测试项目 - 作为测试项目,添加 nuget 包并创建一个带有空测试方法的测试类供您填写。它不是 TDD 的方式,但如果你已经有了它工作得很好的方法。

        【讨论】:

          【解决方案4】:

          NUnit 团队现已创建 Visual Studio Templates for NUnit。只需在 Visual Studio 中安装扩展,您就会发现适用于各种平台的 NUnit 测试项目。

          【讨论】:

            猜你喜欢
            • 2011-01-27
            • 2014-01-18
            • 2016-02-26
            • 2017-02-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-01-12
            相关资源
            最近更新 更多