简体   繁体   中英

Nunit3 console is unable to run tests that are compiled as 32bit (x86)

I've been struggling with this for couple of days. Would appreciate if any1 could help. I've been running tests using Nunit3-console.exe v3.15 with no issues. Recently I had to change Tests project (.dll) from AnyCpu to x86 - because some tests load unmanaged dll library that is 32bit. Now Nunit3-Console.exe refuses to run tests:

nunit3-console.exe c:\Source\PSTS5\NunitTests\bin\Debug\net6.0-windows\NunitTests.dll --testlist=d:\PSTS\TestsToRun.txt

I get this error:

NUnit.Engine.NUnitEngineException : Failed to load the test assembly c:\Source\PSTS5\NunitTests\bin\Debug\net6.0-windows\NunitTests.dll
  ----> System.IO.FileLoadException : Could not load file or assembly 'NunitTests, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null'.
--NUnitEngineException
Failed to load the test assembly c:\Source\PSTS5\NunitTests\bin\Debug\net6.0-windows\NunitTests.dll
   at NUnit.Engine.Drivers.NUnitNetCore31Driver.Load(String assemblyPath, IDictionary`2 settings) in C:\projects\nunit-console\src\NUnitEngine\nunit.engine.core\Drivers\NUnitNetCore31Driver.cs:line 77
   at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage) in C:\projects\nunit-console\src\NUnitEngine\nunit.engine.core\Runners\DirectTestRunner.cs:line 136
   at NUnit.Engine.Runners.DirectTestRunner.LoadPackage() in C:\projects\nunit-console\src\NUnitEngine\nunit.engine.core\Runners\DirectTestRunner.cs:line 126
   at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded() in C:\projects\nunit-console\src\NUnitEngine\nunit.engine.core\Runners\DirectTestRunner.cs:line 235
   at NUnit.Engine.Runners.DirectTestRunner.RunTests(ITestEventListener listener, TestFilter filter) in C:\projects\nunit-console\src\NUnitEngine\nunit.engine.core\Runners\DirectTestRunner.cs:line 182
   at NUnit.Engine.Runners.AbstractTestRunner.Run(ITestEventListener listener, TestFilter filter) in C:\projects\nunit-console\src\NUnitEngine\nunit.engine.core\Runners\AbstractTestRunner.cs:line 168
   at NUnit.Engine.Runners.MasterTestRunner.RunTests(ITestEventListener listener, TestFilter filter) in C:\projects\nunit-console\src\NUnitEngine\nunit.engine\Runners\MasterTestRunner.cs:line 472
   at NUnit.Engine.Runners.MasterTestRunner.Run(ITestEventListener listener, TestFilter filter) in C:\projects\nunit-console\src\NUnitEngine\nunit.engine\Runners\MasterTestRunner.cs:line 150
   at NUnit.ConsoleRunner.ConsoleRunner.RunTests(TestPackage package, TestFilter filter) in C:\projects\nunit-console\src\NUnitConsole\nunit3-console\ConsoleRunner.cs:line 197
--
FileLoadException
Could not load file or assembly 'NunitTests, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at NUnit.Engine.Drivers.NUnitNetCore31Driver.Load(String assemblyPath, IDictionary`2 settings) in C:\projects\nunit-console\src\NUnitEngine\nunit.engine.core\Drivers\NUnitNetCore31Driver.cs:line 71

My Tests dll uses.Net6.0 framework. I've been unable to find Nunit3-console that is compiled in x86. Also in Nunit docu - they state that Nunit3-console 64bit is able to run tests that are 32bit, but it doesn't work for me somehow. I tried --x86 flag:

The x86 option is not available on this platform.

However, I Do able to run tests in Visual Studio 2022. Questions:

  1. Is it possible to run Nunit3-console with 32bit tests dll (.Net6.0)?
  2. Is there any other way to run tests apart from Nunit3-console?

The message The x86 option is not available on this platform gives the clue. It indicates you are running nunit3-console from the package NUnit.ConsoleRunner.NetCore rather than the one from NUnit.ConsoleRunner .

Unfortunately, the exe from each of these packages has the same name, although they do different things. And, of course, it's understandable why you would have chosen the NetCore package in your case.

NOTE: In 3.16 the name of the exe you are using is changed to NUnit3-NetCore-Console.exe This doesn't make it work any different but is intended to make it easier for the developers to understand which program is in use when a user reports a problem.

The runner in the NUnit.ConsoleRunner package is still the "main" runner intended for all uses, including running under .NET Core. It launches a separate process for each test assembly in order to ensure that the tests run in the correct environment. That package does support the --x86 option but you don't normally need to use it for a test assembly built for x86.

You may wonder why there is a.net60 runner at all. It's intended for use with as a tool with the do.net command. When running a tool, you specify 32-bitness by executing a 32 bit build of do.net.exe . Therefore, the -x86 switch can't be supported by the tool because it is already running under a particular do.net.exe at the time that it is able to examine its options.

So... in summary... just switch to using the NUnit.ConsoleRunner package and your x86 tests should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM