问题
I need to run individual C# NUnit tests programmatically. I found another post that was very helpful in showing me how to run an entire set of tests programmatically, but I need to be able to select individual tests.
I thought that setting up a NameFilter would do the trick, but the RemoteTestRunner only seems to think that there's one test in my suite when there are over fifty. Is it really lumping all tests in a single DLL into one gargantuan test? Is there a way that I can separate them out and run individual test cases?
回答1:
I had to pass a filter as well, just executing
TestResult testResult = remoteTestRunner.Run(new NullListener(), null , false, LoggingThreshold.Error);
ended in a NullReferenceException. I quickly created an empty filter
class EmptyFilter : TestFilter
{
public override bool Match(ITest test)
{
return true;
}
}
and passed it to the remoteTestRunner
.
TestResult testResult = remoteTestRunner.Run(new NullListener(), new EmptyFilter() , false, LoggingThreshold.Error);
That worked. What one could invest a little is to search whether NUnit already has a similar Filter that could be reused rather than creating a custom one.
回答2:
I had to use a SimpleNameFilter and pass to its constructor the name of the unit test I wanted to run. Here's what I have:
SimpleNameFilter filter = new SimpleNameFilter("Google.Maps.Test.Integrations.GeocodingServiceTests.Empty_address");
TestResult testResult = remoteTestRunner.Run(new NullListener(), filter, false, LoggingThreshold.Error);
You can get the fully-qualified test name by either figuring it out from the test itself or by looking at your test's Properties in the NUnit program.
来源:https://stackoverflow.com/questions/15980724/running-individual-nunit-tests-programmatically