Hitta testmetoder via reflexion

This commit is contained in:
2019-11-18 23:58:04 +01:00
parent 094b1dfc34
commit 3c2a38d35f
4 changed files with 37 additions and 4 deletions

View File

@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Linq;
using System.Text;
namespace TestingLib
@ -32,5 +35,24 @@ namespace TestingLib
testInfo.MethodName = methodName;
TestResults.Add(testInfo);
}
public static void RunTests()
{
foreach (MethodInfo method in GetTestMethods())
{
var instanceOfTestClass = Activator.CreateInstance(method.DeclaringType);
method.Invoke(instanceOfTestClass, null);
}
}
private static List<MethodInfo> GetTestMethods()
{
var q = from t in Assembly.GetExecutingAssembly().GetTypes()
from m in t.GetMethods()
from att in m.GetCustomAttributes(true)
where att.GetType() == typeof(CheckThisMethod)
select m;
return q.ToList();
}
}
}