I'm trying to run NUNIT tests through Reflection in C#. I load the assemble and get the methods, then I want to filter out for methods only assigned the NUnit.FrameWork.TestAttribute.
I have tried this and it doesn't work:
var testTypes = from t in ltAssm.GetTypes()
let attributes = t.GetCustomAttributes(typeof(NUnit.Framework.TestFixtureAttribute), true)
where attributes != null && attributes.Length > 0
orderby t.Name
select t;
foreach (var type in testTypes)
{
var testMethods = from m in type.GetMethods()
let attributes = m.GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), true)
where attributes != null && attributes.Length > 0
orderby m.Name
select m;
foreach (var method in testMethods)
{
methods.Add(method);
}
}
no methods picked up even though there are 50.
Even running this simple line doesn't pick anything up:
var xx = classMethods[11].GetCustomAttributes(typeof(NUnit.Framework.TestAttribute), false);
I also tried instantiating the type and still nothing.
Those same methods have another custom attribute which I created and assigned to them, if I attempt to retrieve the methods using that Attrib, then they are retrieved.
Anyone know of something special that needs to be done for Reflection to recognize Nunit's TestAttribute?