【问题标题】:Using category expressions in Nunit console runner在 Nunit 控制台运行器中使用类别表达式
【发布时间】:2013-08-13 14:10:46
【问题描述】:

在使用 /include 或 /exclude 语句时,我正在阅读有关类别表达式的 this link。我希望能够仅包含运行测试以用完两个可用测试或运行所有测试但使用 /include:A+B 或 /exclude:A。但是,由于某种原因,它显示了错误的要运行和/或不运行的测试数量。这是为什么?

谁能给我一个关于如何分类表达式(通过操作源代码)并添加如何在控制台中运行命令的示例?

基本上我所做的是:

using System;
using NUnit;
using NUnit_Application;
using NUnit.Framework;

namespace NUnit_Application.Test
{
[TestFixture]
[Category("MathS")] 
public class TestClass
{
    [TestCase]
    [Category("MathA")]
    public void AddTest()
    {
        MathsHelper helper = new MathsHelper();
        int result = helper.Add(20, 10);
        Assert.AreEqual(40, result);
    }

    [TestCase]
    [Category("MathB")]
    public void SubtractTest()
    {
        MathsHelper helper = new MathsHelper();
        int result = helper.Subtract(20, 10);
        Assert.AreEqual(10, result);
    }
}
}

我的命令行语句是 nunit-console /framework:net-4.0 /run:NUnit_Application.Test.TestClass.AddTest C:~\NUnit_Application\NUnit_Application\NUnit_Application.Test\bin\Debug\NUnit_Application.Test.dll /include:"MathA"

问题是,控制台熟悉命令的含义,并且说它包含数学 A 类别。但是,它显示零测试已运行且零测试尚未运行。

我正在运行控制台运行程序 NUnit 2.6.2。

【问题讨论】:

    标签: c# nunit nunit-console


    【解决方案1】:

    这是我最初使用的命令:

    nunit-console /framework:net-4.0 /run:NUnit_Application.Test.TestClass.AddTest C:~\NUnit_Application\NUnit_Application\NUnit_Application.Test\bin\Debug\NUnit_Application.Test.dll /include:"MathA"
    

    我注意到如果我只调用 TestClass 而不是单个测试用例,它会起作用:

    nunit-console /framework:net-4.0 /run:NUnit_Application.Test.TestClass C:~\NUnit_Application\NUnit_Application\NUnit_Application.Test\bin\Debug\NUnit_Application.Test.dll /include:"MathA"
    

    【讨论】:

      【解决方案2】:

      我认为这是因为您拥有具有该属性的整个班级:

      [Category("MathS")]
      

      所以它跳过它。

      【讨论】:

      • 我删除了 [Category("MathS")] 但我仍然遇到同样的问题。
      • 是的,我确实重新编译了。也许给我一个例子?我只是想测试一下 NUnit 的特性并学习如何将它用于类别表达式。
      • 我让它工作了。唯一奇怪的是为什么当我包含:MathA+MathB 时,没有一个测试运行。但如果我排除:MathA+MathB,它会说运行了 2 个测试。这是为什么呢?
      • 根据 NUnit 文档(您的链接),MathA+MathB 表示 两个 类别——即测试必须同时包含或排除在两个类别中。我认为您想要的是/include:MathA,MathB,它应该运行两个类别中任一(或两者)中的测试。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多