我不了解在TFS中可以使用哪些设置类型,因为我没有使用TFS,但我知道在NUnit和MSTest中都可以使用Categories。
使用NUnit的解决方案
对于NUnit,你可以使用Category
属性来标记单个测试甚至整个测试夹具:
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
[Category("IntegrationTest")]
public class IntegrationTests
{
}
}
或者
namespace NUnit.Tests
{
using System;
using NUnit.Framework;
[TestFixture]
public class IntegrationTests
{
[Test]
[Category("IntegrationTest")]
public void AnotherIntegrationTest()
{
}
}
}
并且只运行使用nunit-console.exe的那些测试:
nunit-console.exe myTests.dll /include:IntegrationTest
MSTest解决方案
MSTest的解决方案非常类似:
namespace MSTest.Tests
{
[TestClass]
public class IntegrationTests
{
[TestMethod]
[TestCategory("IntegrationTests")
public void AnotherIntegrationTest()
{
}
}
}
但是在这里,您必须使用该属性标记所有测试,不能用它来装饰整个类。
然后,就像使用 NUnit 一样,在 IntegrationTests 类别中只执行那些测试:
使用 VSTest.Console.exe
Vstest.console.exe myTests.dll /TestCaseFilter:TestCategory=IntegrationTests
使用 MSTest.exe
mstest /testcontainer:myTests.dll /category:"IntegrationTests"
编辑
你也可以使用VS的TestExplorer来执行特定的测试类别。
![输入图像描述](https://istack.dev59.com/Ekwih.webp)
(来源:s-msft.com)
如上图所示,在TestExplorer的左上角可以选择一个类别。选择Trait并只执行想要的类别。
有关更多信息,请参见MSDN。