1 year ago
#122610
mikus
Nunit-console fails to run tests depending on ASP.NET Core dependencies
I have an issue running nUnit Tests that depend on ASP.NET core framework.
They run perfectly fine and green in VisualStudio 2019. I can also run them in command line using 'dotnet test'. However, whenever I run them using nunit-console I get the following error:
System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.AspNetCore.Http,
Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The system cannot find the file specified.
This only applies to tests which use HttpContext or are mocking the session - so they indeed have dependency on ASP (rest of the tests run fine):
var mockSession = new Mock<ISession>();
// or
var httpContext = new DefaultHttpContext();
All the projects are .net 5.0 and targeting only 5.0. I use nUnit 3.13.2 and NUnit3TestAdapter 4.2.1. I used nunit-consolerunner 3.14 The UnitTest project references my main ASP.NET Core MVC project. I have tried numerous ways to get those assemblies into the output folder, but this particular one newer is copied and I don't want to do it manually. I have also tried adding the framework reference to the UnitTest project directly (in csproj), but no help:
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Since nunit-console normally runs in full framework, I have also tried running the core version of it: nunit.consolerunner.netcore (also 3.14). But with the same result.
The command line I'm using:
C:\Users\XXX\.nuget\packages\nunit.consolerunner.netcore\3.14.0\tools\netcoreapp3.1\any\nunit3-console.exe .\bin\Debug\net5.0\MyProject.UnitTests.dll
I also tried the version which was earlier recommended at github for forcing particular runtime to be used:
dotnet.exe --fx-version 5.0.13 "C:\Users\XXX\.nuget\packages\nunit.consolerunner.netcore\3.14.0\tools\netcoreapp3.1\any\nunit3-console.dll" .\bin\Debug\net5.0\MyProject.UnitTests.dll
Is it just a limitation of the not-so-mature yet nunit-consolerunner.netcore. Or maybe it's just missing setup of the project?
asp.net-core
nunit
nunit-3.0
nunit-console
0 Answers
Your Answer