I want to run NUnit tests from my code. To be more specific I have an Web API (.net core) that recieves set of test names that needs to be run and after the run, the endpoint will return set of results.
The tests are in another .dll (another project that's using Microsoft.Playwright and Serilog to log to ElasticSearch - it's .net core also but it has classes marked as [TextFixutre]).
At first, I just wanted to check if the RemoteTestRunner is loading all of my tests
here is the demo code:
[HttpPost]
[Route("/api/TestSuiteRun/Run")]
public IActionResult RunTestSuite([FromBody] AutomationAPI.Models.TestSuite testSuite)
{
try
{
CoreExtensions.Host.InitializeService();
TestSuiteBuilder builder = new TestSuiteBuilder();
TestPackage testPackage = new TestPackage(@"C:\Desktop\Automation-v2\Automation-v2\bin\Debug\netcoreapp3.1\Automation-v2.dll");
RemoteTestRunner remoteTestRunner = new RemoteTestRunner();
remoteTestRunner.Load(testPackage);
NUnit.Core.TestSuite suite = builder.Build(testPackage);
NUnit.Core.TestSuite test = suite.Tests[0] as NUnit.Core.TestSuite;
var numberOfTests = ((TestFixture)test.Tests[0]).TestCount;
foreach (TestMethod t in ((TestFixture)test.Tests[0]).Tests)
{
Console.WriteLine(t.TestName.Name);
}
return StatusCode(200);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
return StatusCode(500);
}
}
but I'm ending up with following exception on remoteTestRunner.Load(testPackage) line:
"Could not load type 'System.Runtime.Remoting.Messaging.ILogicalThreadAffinative' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
and I don't know why is this happening. Any ideas?
As for the second question that I have, is it possible to pass TestCaseSource to the test with RemoteTestRunner or it must be written in the .dll explicitly (before load in the RemoteTestRunner) like this:
[Test, TestCaseSource(typeof(UserProvider), "ProvideUsers")]
public async Task ExportPPTTimeTestAsync(User currentUser)
{...