I'm trying to add test method using category by reading DLL using reflection, something like this:
if the test method is
[TestMethod, Category("xyz"), Category("abc")]
public void VerifySomething()
{
//some code
}
I'm reading the dll using reflection like this -
Assembly _assembly = Assembly.LoadFile("Mydll.dll");
Type[] types = _assembly.GetExportedTypes();
foreach (Type type in types)
{
Attribute _classAttribute = Type.GetCustomAttribute(typeof(TestClassAttribute));
if (_classAttribute != null)
{
TreeNode _node = new TreeNode();
_node.Test = type.Name;
if(type.name.Contains("testbase"))
continue;
MemberInfo[] members = type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod);
foreach (MemberInfo member in members)
{
Attribute _classAttribute = type.GetCustomAttribute(typeof(TestClassAttribute), true);
{
if (_classAttribute != null)
{
foreach (var attribute in (IEnumerable<TestCategoryAttribute>)_classAttribute)
{
foreach (var category in attribute.TestCategories)
{
if (category == "someCategory")
treeViewMobile.Nodes["someCategory"].Nodes["someChildNode"].Nodes.Add(category);
}
}
}
using this i'm unable to add test methods filtered by particular category inside test method. I'm new to reflection, can anybody help me out here. Any place where i can learn reflection will also help.
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire