nunit-console: Test runner does not close fired up proceseses.
When I fire up a test runner, it starts two processes:

After the runner has performed the test round it should close the processes. I try to accomplish this by setting one of the following configurations:
static void Main(string[] args)
{
// Get an interface to the engine
using (ITestEngine engine = TestEngineActivator.CreateInstance())
{
var settings = engine.Services.GetService<ISettings>();
settings.SaveSetting("DisposeRunners", true);
settings.SaveSetting("StopOnError", true);
settings.SaveSetting("DebugAgent", false);
settings.SaveSetting("DebugTests", false);
// Create a simple test package - one assembly, no special settings
TestPackage package = new TestPackage(@"E:\programming\FaultifyNew\Faultify\Benchmark\Faultify.Benchmark.NUnit\bin\Debug\netcoreapp3.1\test-duplication-0\Faultify.Benchmark.NUnit.dll");
package.AddSetting("DisposeRunners", true);
package.AddSetting("StopOnError", true);
package.AddSetting("DebugAgent", false);
package.AddSetting("DebugTests", false);
// Get a runner for the test package
using (ITestRunner runner = engine.GetRunner(package))
{
// Run all the tests in the assembly
XmlNode testResult = runner.Run(null, TestFilter.Empty);
runner.StopRun(true);
runner.Unload();
}
};
Console.ReadLine();
}
None of them seem to work and have no effect. How can I make sure the processes fired-up by the runner are closed? They are locking my files which prevents me to use them.’
Info “NUnit.Engine” Version=“3.12.0” netcoreapp3.1
Files
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (17 by maintainers)
Yea that is correct! Also see: https://stackoverflow.com/questions/123391/how-to-unload-an-assembly-from-the-primary-appdomain#:~:text=You can not unload an,the life of the appdomain.
Currently, I am trying to get XUnit working for my app but also there I have issues with loading/unloading assemblies. There are areas of overlap. Perhaps after I am finished with that I have a better perspective on how to resolve this issue. Upto now I was a bit unfamiliar with how assemblies were loaded into an Appdomain.
Side note: I think we’ll also need to enable
isCollectableonCustomAssemblyLoadContext.Docs: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext.-ctor?view=net-5.0#System_Runtime_Loader_AssemblyLoadContext__ctor_System_Boolean_
That would be OK in Mono.Cecil, because it’s designed for modifying an assembly. However, it seems slightly unsafe in the unusual case case where two processes might be trying to modify the same assembly. However, since the metadata assembly we use is expressly designed for read-only use, I think we can just tell people “don’t do that!” 😉
Our policy is that two of us have to review your PR and approve it for merging. I can do one of them and @ChrisMaddock should probably do the other since he wrote the .NET Core framework driver.