First of all, you need to define the criteria by which you will distinguish test methods from other methods.
If you are using a special tool/library for testing, like NUnit, or VisualStudio.TestTools.UnitTesting, then this may be relatively easy; if you have created your own testing library, then you would probably create a Custom Attribute to adorn test methods with.
In the case whatever you use doesn't provide a way to get at all the methods easily ... I assume that's the case here ... you are going to select a .dll, or .dll's, and search recursively, using recursion, for Methods that meet your criteria.
A recursive search is going to have this kind of "flow:"
foreach FileInfo theFileInfo in AWholeBunchOfDLLFiles
Assembly theAssembly = Assembly.LoadFrom(theFileInfo.FullName);
foreach Type theType in theAssembly.GetTypes()
foreach MethodInfo theMethod in theType.GetMethods()
foreach Attribute attr in Attribute.GetCustomAttributes(theMethod)
if (attr.GetType() == typeof (YourTestMethodAttribute))
{
YourTestMethodAttribute mta = attr as MyTestMethodAttribute;
Console.WriteLine
(
"Method {0} with MyTestMethodAttribute ID: {1}",
mInfo.Name,
mta.ID
);
}
This is an example of an actual Custom Attribute that would work with the code shown above:
public class YourTestMethodAttribute : Attribute
{
private static int _id;
protected int ID
{
set { _id = value; }
get { return _id; }
}
public YourTestMethodAttribute()
{
ID++;
}
}