您可以使用 MSTest.exe 或 VSTest.console.exe 通过命令行运行 TestMethods。可以在批处理文件中调用 MSTest.exe 或 VSTest.console.exe。
分配用户定义的 testcategory 属性来对您的测试进行分组。请参考Defining Test Categories to Group Your Tests。例如
[TestCategory("Nightly"),
TestCategory("Weekly"),
TestCategory("ShoppingCart"),
TestMethod()]
public Void DebitTest()
{
}
[TestCategory("Nightly"),
TestCategory("Weekly"),
TestCategory("ShoppingCart"),
TestMethod()]
public Void CreditTest()
{
}
[TestCategory("Nightly"),
TestCategory("Daily"),
TestCategory("ShoppingCart"),
TestMethod()]
public Void BVTTest1()
{
}
[TestCategory("Nightly"),
TestCategory("Daily"),
TestCategory("ShoppingCart"),
TestMethod()]
public Void BVTTest2()
{
}
通过 TestCategory 的 VSTest.Console.exe 组运行测试
Vstest.console.exe myTestProject.dll /TestCaseFilter:”TestCategory=Nightly"
按测试类别按 MSTest.exe 组运行测试
mstest /testcontainer:MyTestprojectName.dll /category:"Nightly"
mstest /testcontainer:MyTestprojectName.dll /category:"Daily"
请参阅MSDN Link 了解本主题中的更多命令行选项。