假设我有以下几种情况:
@TagOne
Scenario: ScenarioA
...
@TagOne
Scenario: ScenarioB
...
@TagOne @TagTwo
Scenario: ScenarioC
...
@TagTwo
Scenario: ScenarioD
...
我如何获得场景列表以及相关标签?
例如,鉴于上述数据,我想要这样的东西:
ScenarioA, TagOne
ScenarioB, TagOne
ScenarioC, TagOne|TagTwo
ScenarioD, TagTwo
我需要某种机器可读的形式,理想情况下,我想制作一个维恩图或UpSet图等。
我已经设法使用反射从测试DLL中提取方法名称等,但是我无法弄清楚如何识别方案
[更新]
我想我可能已经解决了...
这段代码似乎提取了我想要的所有信息:
string dllPath = @"Tests.dll";
Assembly assembly = Assembly.LoadFrom(dllPath);
var currentNamespace = string.Empty;
var currentFeature = string.Empty;
foreach (var type in assembly.GetTypes())
{
foreach (var methodInfo in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
var featureName = string.Empty;
var isScenario = false;
var tags = new List<string>();
foreach (var att in methodInfo.CustomAttributes.ToList())
{
var args = att.ConstructorArguments.ToList();
if (att.AttributeType.Name == "TestCategoryAttribute")
{
tags.Add(args[0].ToString());
isScenario = true;
}
else if (att.AttributeType.Name == "TestPropertyAttribute" && args[0].ToString() == "\"FeatureTitle\"")
{
featureName = args[1].ToString().TrimStart('"').TrimEnd('"');
}
}
if (isScenario)
{
if (currentNamespace != type.Namespace)
{
Debug.WriteLine($"Namespace: {type.Namespace}");
currentNamespace = type.Namespace;
}
if (currentFeature != featureName)
{
Debug.WriteLine($" Feature: {featureName}");
currentFeature = featureName;
}
Debug.WriteLine($@" Scenario: {featureName}\{methodInfo.Name}");
Debug.WriteLine($" Tags: {String.Join(",", tags)}");
}
}
}