I am trying to create my own nunit test interface. First I grab a list of all test case names in the assembly, like so:
public List<TestName> GetTests(string assemblyPath, int runnerId)
{
var tests = new List<NUnit.Core.TestName>();
//load assembly.
var assembly = Assembly.LoadFile(assemblyPath);
//get testfixture classes in assembly.
var testTypes = from t in assembly.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)
{
//get test methods in class.
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)
{
tests.Add(new NUnit.Core.TestName
{
RunnerID = runnerId,
FullName = type.FullName + "." + method.Name,
Name = method.Name
});
}
}
return tests;
}
Next I display the tests, and want to be able to click on one to run it using the RemoteTestRunner:
//start new test.
var testName = new TestName
{
FullName = fullName,
//TestID = new TestID(???),
Name = name,
RunnerID = RunnerId
};
var filter = new NameFilter(testName);
Runner.BeginRun(Listener, filter);
However, when passing a NameFilter into the runner on run, it requires the TestName in the NameFilter to have the TestID set. If it isn't set then the runner finds 0 test cases to run. I don't have the TestID obviously, all I have is the full test name. How do I retrieve the TestID, given the full test name, so that I can successfully run the individual test case?