Reputation: 353
My setup
CoreExtensions.Host.InitializeService();
package = new TestPackage(pathToTestDll);
builder = new TestSuiteBuilder();
suite = builder.Build(package);
And running (note that tests are the valid list of NUnitTestMethods retrieved from the suite
foreach (NUnitTestMethod t in tests)
{
try
{
var res = t.RunTest();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
I get this as the exception stack:
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at NUnit.Core.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args) at NUnit.Core.TestMethod.RunTestMethod() at NUnit.Core.TestMethod.RunTestCase(TestResult testResult)
Note that t.RunTest(); does not fail rather the test just fails at running and HasError flag is set...
The nunit.core and nunit.core.interfaces are the same files in both my test package and runner package
Upvotes: 1
Views: 170
Reputation: 13681
You initialize CoreServices but make no use of them because you are running tests at a very low level. Using internal classes, not intended for general purpose use, is always risky. But it's especially risky if you put them together piecemeal rather than using them in the way that NUnit itself does.
If you want to run the tests programatically (that may not be such a great idea, but it appears to be what you want to do) then I suggest you select and use one of the NUnit runners to take care of the details for you. Select from SimpleTestRUnner, RemoteTestRunner or TestDomain, depending on how you want the tests to run, and where.
TestDomain will run them in a separate AppDomain, which is generally easiest and safest. RemoteTestRunner will run them in the current AppDomain, redirecting output. SimpleTestRunner is the lowest level runner (but still way higher-level than what you are doing) and just runs the tests where they are. Note that you can't run tests in the same AppDomain (Remote and Simple) unless you have copied all the test files, their references and the NUnit files into the same directory.
Upvotes: 1