我想获得单元测试项目/解决方案中所有测试方法的列表。我使用的是MSTest框架。我想获得所有测试方法的列表,这样我就可以编写一些逻辑来实现所有可用测试的日志记录,以及执行什么和正在执行哪个测试等。
我是这个领域一岁的新手。因此,请提供详细的解释或代码。
发布于 2015-10-11 16:53:35
我发现了一篇关于如何在Nunit中做到这一点的帖子,并且能够在MSTest中做到这一点。
var test= new List ();
var testTypes = from t in assembly.GetTypes()
orderby t.Name
select t;
foreach (var type in testTypes)
{
var testMethods = from m in type.GetMethods()
let attributes = m.GetCustomAttributes(typeof(TestMethodAttribute), true)
where attributes != null && attributes.Length > 0
orderby m.Name
select m;
foreach (var method in testMethods)
{
tests.Add(method.Name);
}
}https://stackoverflow.com/questions/33058921
复制相似问题