简体   繁体   English

Nunit:为特定测试用例添加类别

[英]Nunit: Add Category to specific test cases

I would like to run a small set of NUnit test cases as a pre-checkin sanity check, and a more comprehensive set of test cases on my on-checkin and nightly test runs. 我想运行一小组NUnit测试用例作为预签入健全性检查,并在我的on-checkin和nightly测试运行中运行更全面的测试用例。

So I had hoped I could decorate certain tests cases with the "Category" attribute, and have only those test cases run at pre-checkin time. 所以我希望我能用“类别”属性修饰某些测试用例,并且只有那些测试用例在预签入时运行。 However, that doesn't seem to work - if I include the category then all test cases are run. 但是,这似乎不起作用 - 如果我包含该类别,则运行所有测试用例。

Is there a way to restrict the number of test cases being run via categories? 有没有办法限制通过类别运行的测试用例数量?

[TestFixture]
public class TestAddition
{
    [TestCase(1, 2, 3), Category("PreCheckin")]
    [TestCase(2, 4, 6)]
    [TestCase(3, 6, 9)]
    public void AdditionPassTest(int first, int second, int expected)
    {
        var adder = new Addition();
        var total = adder.DoAdd(first, second);
        Assert.AreEqual(expected, total);
    }
}

If I try to run this: 如果我尝试运行这个:

C:\> "C:\Program files (x86)\Nunit 2.6.4\bin\nunit-console.exe" /nologo ^
     NUnitTestCase.dll /labels /include=PreCheckin
ProcessModel: Default    DomainUsage: Single
Execution Runtime: net-3.5
Included categories: PreCheckin
***** NUnitTestCase.TestAddition.AdditionPassTest(1,2,3)
***** NUnitTestCase.TestAddition.AdditionPassTest(2,4,6)
***** NUnitTestCase.TestAddition.AdditionPassTest(3,6,9)

Tests run: 3, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0743007328107035 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

I was wanting only the single test case (1, 2, 3) to be run 我只想要运行单个测试用例(1,2,3)

You use Category attribute for all tests now. 您现在为所有测试使用Category属性。 Change code to this one :) 将代码更改为此:)

[TestFixture]
public class TestAddition
{
    [TestCase(1, 2, 3, Category = "PreCheckin")]
    [TestCase(2, 4, 6)]
    [TestCase(3, 6, 9)]
    public void AdditionPassTest(int first, int second, int expected)
    {
        var adder = new Addition();
        var total = adder.DoAdd(first, second);
        Assert.AreEqual(expected, total);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM