我不知道可以在 TFS 中使用的设置类型,因为我没有使用 TFS,但我知道可以在 NUnit 和MSTest。
使用 NUnit 的解决方案
使用 NUnit,您可以使用 Category-Attribute 标记单个测试甚至整个夹具:
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()
{
}
}
}
但是这里你必须用那个属性标记所有的Test,它不能用来装饰整个类。
然后,和 NUnit 一样,只执行 IntegrationTests 类别中的那些测试:
使用 VSTest.Console.exe
Vstest.console.exe myTests.dll /TestCaseFilter:TestCategory=IntegrationTests
使用 MSTest.exe
mstest /testcontainer:myTests.dll /category:"IntegrationTests"
编辑
您还可以使用 VS 的 TestExplorer 执行某些测试类别。
(来源:s-msft.com)
如上图所示,您可以在 TestExplorer 的左上角选择一个类别。选择 Trait 并仅执行您想要的类别。
请参阅MSDN 了解更多信息。