我希望在提交前进行一次小规模的 NUnit 测试以确保正常,同时还希望在提交后和每晚的测试中运行更全面的测试用例。因此,我希望可以使用“Category”属性装饰某些测试用例,并仅在提交前运行这些测试用例。但是,这似乎并不起作用 - 如果我包含类别,则会运行所有测试用例。是否有一种通过分类来限制运行测试用例数量的方法?
如果我尝试运行这个代码:
[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);
}
}
如果我尝试运行这个代码:
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
我只希望运行单个测试用例 (1, 2, 3)