[英]Extract test cases from visual studio 2013
如何在不使用TFS的情况下将具有“ TestClass”属性的所有类及其具有“ TestMethods”属性的所有方法提取到外部文件(如.txt或excel类型)中?
There are probably tools but here is a simple implementation using reflection: 可能有工具,但这是使用反射的简单实现:
var assembly = Assembly.LoadFile("xxx.dll");
var testClasses = assembly.GetTypes()
.Where(c => c.GetCustomAttribute<TestClassAttribute>() != null);
foreach (var testClass in testClasses)
{
Console.WriteLine("Found test class " + testClass.FullName);
var testMethods = testClass.GetMethods().Where(m => m.GetCustomAttribute<TestMethodAttribute>() != null);
foreach (var testMethod in testMethods)
{
Console.WriteLine("Found test method " + testMethod.Name);
}
}
[TestMethod]
public void list__all_unit_tests()
{
string sDLL = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
string sFilePath = string.Format("{0:s}\\{1:s}.DLL", System.IO.Directory.GetCurrentDirectory(), sDLL);
var assembly = System.Reflection.Assembly.LoadFile(sFilePath);
var testClasses = assembly.GetTypes()
.Where(m => m.GetCustomAttributes(typeof(TestClassAttribute),false)!=null);
foreach (var testClass in testClasses)
{
var testMethods = testClass.GetMethods()
.Where(m => m.GetCustomAttributes(typeof(TestMethodAttribute),true).Length !=0);
foreach (var testMethod in testMethods)
{
Debug.Print(string.Format("class,{0:s}, method,{1:s} ", testClass.FullName , testMethod.Name));
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.