Nunit:将类别添加到特定的测试用例中
本文关键字:测试用例 添加 Nunit | 更新日期: 2023-09-27 18:26:37
我想运行一小组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)
现在所有测试都使用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);
}
}