在Nunit控制台运行器中使用类别表达式

时间:2013-08-13 14:10:46

标签: c# nunit nunit-console

使用/ 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,即控制台运行程序。

2 个答案:

答案 0 :(得分:2)

这是我最初使用的命令:

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"

答案 1 :(得分:0)

我认为这是因为你的全班都有属性:

[Category("MathS")]

所以它会跳过它。