I am trying to execute Nunit test cases writen in c# using a console program. So far i tried different ways to do it but not able to find a perfect way of approach to achieve the same.
Approach 1: Using NUnitTestAdapter package. This package is older and not able to run the test which are created using the latest nunit version 3.2.1. But its working fine with older versions like 2.6.4
Added NUnitTestAdapter package to the solution Then tried the below code
CoreExtensions.Host.InitializeService();
TestSuiteBuilder builder = new TestSuiteBuilder();
TestPackage testPackage = new TestPackage(@"path to dll");
RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
remoteTestRunner.Load(testPackage);
TestSuite suite = builder.Build(testPackage);
TestSuite test = suite.Tests[0] as TestSuite;
var numberOfTests = ((TestFixture)test.Tests[0]).TestCount;
int i = 0;
foreach (TestMethod t in ((TestFixture)test.Tests[0]).Tests)
{
Console.WriteLine(t.TestName.Name);
//TestName testName = ((TestMethod)((TestFixture)test.Tests[0]).Tests[i]).TestName;
TestFilter filter = new NameFilter(t.TestName);
TestResult result = test.Run(new NullListener(), filter);
ResultSummarizer summ = new ResultSummarizer(result);
NUnit.Core.NUnitFramework.Assert.AreEqual(1, summ.ResultCount);
i++;
}
Can i get any updated version of this then this will a fine solution.
Approach 2: Using Nunit3-console
Added the reference to nunit3.console.exe to my project and tried with below code
string path = @"path to dll";
NUnit.ConsoleRunner.Program.Main(new[] { path });
This is throwing an error saying "Either assembly contains no tests or proper test driver has not been found"
Can anybody let me know how can we run the tests with execution log?