C# – Running NUnit Tests In a C# Console App

cnunit

I need to run NUnit tests programmatically in a console app. Using NUnit's nunit-console.exe is not an option. My current code is:

var testRunner = new SimpleTestRunner();
var package = new TestPackage("MyTests.dll", new List<string> { ("c:\MyTests\MyTests.dll" });
testRunner.Load(package);

When I call Load, NUnit looks for the dll in the current process's directory. So I get a FileNotFoundException for something like "c:\MyTestRunner\bin\debug\MyTests.dll".

How can I force it to look for the dll in a different directory?

Best Answer

You can change the current directory

Directory.SetCurrentDirectory(@"c:\MyTestRunner\bin\debug\");

Update:

It seems this is not so simple. I`v looked around, there is an article and stack question on this issue.

Hope it helps

Related Topic