【发布时间】:2018-03-12 10:31:56
【问题描述】:
我正在尝试获取 MSTest 中已运行 TestMethod 的特定 TestMethod 的 TestCategory 名称。
如果一个 TestMethod 有多个 TestCategory,该方法是针对哪个特定的 TestCategory 调用的?
我正在使用下面的代码获取该方法的所有 TestCategories,但如何找到调用该方法的特定类别。
[TestMethod, TestCategory("Reg"), TestCategory("Smoke"), TestCategory("Sanity"), TestCategory("PathTest")]
public void TestMethod_testCatetory()
{
var method = MethodBase.GetCurrentMethod();
foreach (var attribute in (IEnumerable<TestCategoryAttribute>)method
.GetCustomAttributes(typeof(TestCategoryAttribute), true))
{
foreach (var category in attribute.TestCategories)
{
Console.WriteLine(category);
}
}
}
从 cmd 将使用以下命令调用它
C:\VSTest.Console.exe LocationOfDLL /TestCaseFilter:"TestCategory=Smoke"
是否可以获取用于调用方法的 TestCategory is Smoke?
【问题讨论】:
标签: c# mstest azure-pipelines