我想运行一小组NUnit测试用例作为预签入式完整性检查,并在我的on-checkin和nightly测试运行中运行更全面的测试用例。
所以我希望我能用“类别”属性修饰某些测试用例,并且只有那些测试用例在预签入时运行。但是,这似乎不起作用 - 如果我包含该类别,则运行所有测试用例。
有没有办法限制通过类别运行的测试用例数量?
[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)
答案 0 :(得分:6)
现在为所有测试使用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);
}
}