Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUnit Console cannot run tests with TargetFramework "net5.0" #858

Closed
GitClickOk opened this issue Jan 8, 2021 · 27 comments
Closed

NUnit Console cannot run tests with TargetFramework "net5.0" #858

GitClickOk opened this issue Jan 8, 2021 · 27 comments
Labels
Enhancement NetCoreRunner Issue related to the .NET Core console runner

Comments

@GitClickOk
Copy link

If it matters, I'm using:

  • NUnit Console Runner 3.12.0-beta1
  • NUnit: 3.13.0
  • NUnit3TestAdapter: 4.0.0-beta.1

When I compile my tests with TargetFramework "netcoreapp3.1", the console works fine.

When I compile my tests with TargetFramework "net5.0", the console cannot execute them.

This is the output:

NUnit Console Runner 3.12.0-beta1
Copyright (c) 2020 Charlie Poole, Rob Prouse
Friday, January 8, 2021 2:17:14 PM

Runtime Environment
   OS Version: Microsoft Windows 10.0.19042
  Runtime: .NET Core 3.1.10

Test Files
    .\MyTests.dll


Errors, Failures and Warnings

1) Invalid : MyTests.dll
Unable to load one or more of the requested types.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Run Settings
    DisposeRunners: True
    WorkDirectory: path\to\src\bin\Debug\net5.0
    NumberOfTestWorkers: 4

Test Run Summary
  Overall result: Failed
  Test Count: 0, Passed: 0, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2021-01-08 17:17:14Z
    End time: 2021-01-08 17:17:14Z
    Duration: 0.169 seconds

Looking the console output I see the runner is using "Runtime: .NET Core 3.1.10". I cannot find an option in command line to change this (maybe it is not detecting correctly yet?). I tested adding the parameter --framework=net5.0, but it outputs:
The framework= option is not available on this platform.

My questions:

  1. Is it expected? The NUnit Console Runner is not ready to .net5 yet?
  2. If it is not expected, what I'm doing wrong and what I can do to fix it?
@CharliePoole
Copy link
Collaborator

The output displayed indicates that the console runner itself targets .net core 3.1. So too does the engine used by the runner. However, it says nothing about the process in which your tests are running.

When we build the runner, we actually run tests under .NET 5.0, if it is installed. However, it's possible that the beta-1 release is still not able to handle that. I suggest trying the latest -devpre-release on our myget feed.

@ChrisMaddock you probably have a more complete answer for this than I do.

@GitClickOk
Copy link
Author

I have updated the console with latest version in myGet 3.12.0-dev-04990, but I received the same error:

NUnit Console Runner 3.12.0-dev-04990
Copyright (c) 2020 Charlie Poole, Rob Prouse
Friday, January 8, 2021 5:19:01 PM

Runtime Environment
   OS Version: Microsoft Windows 10.0.19042
  Runtime: .NET Core 3.1.10

Test Files
    .\MyTests.dll


Errors, Failures and Warnings

1) Invalid : MyTests.dll
Unable to load one or more of the requested types.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Run Settings
    DisposeRunners: True
    WorkDirectory: path\to\src\bin\Debug\net5.0
    NumberOfTestWorkers: 4

Test Run Summary
  Overall result: Failed
  Test Count: 0, Passed: 0, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2021-01-08 20:19:01Z
    End time: 2021-01-08 20:19:01Z
    Duration: 0.188 seconds

@GitClickOk
Copy link
Author

AND in myGet page says in "Target frameworks" section ".NETCoreApp 3.1: 3.1.0.0", no mention to "net5.0":
myGet

@GitClickOk
Copy link
Author

GitClickOk commented Jan 8, 2021

Finally (don't take me wrong, I'm not being annoying, just helping on debugging).
I created the default console app with dotnet new nunit. Then I executed dotnet build. I changed to bin\Debug\net5.0 folder and executed nunit .\NUnitConsoleBug.dll and the same error happens:

NUnit Console Runner 3.12.0-dev-04990
Copyright (c) 2020 Charlie Poole, Rob Prouse
Friday, January 8, 2021 6:05:36 PM

Runtime Environment
   OS Version: Microsoft Windows 10.0.19042
  Runtime: .NET Core 3.1.10

Test Files
    .\NUnitConsoleBug.dll


Errors, Failures and Warnings

1) Invalid : C:/NUnitConsoleBug/bin/Debug/net5.0/NUnitConsoleBug.dll
Unable to load one or more of the requested types.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Run Settings
    DisposeRunners: True
    WorkDirectory: C:\NUnitConsoleBug\bin\Debug\net5.0
    NumberOfTestWorkers: 4

Test Run Summary
  Overall result: Failed
  Test Count: 0, Passed: 0, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2021-01-08 21:05:36Z
    End time: 2021-01-08 21:05:37Z
    Duration: 0.236 seconds

Results (nunit3) saved as TestResult.xml

Anyway, if it can help, this is the content of the auto generated project file, targeting .net5:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NUnit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
  </ItemGroup>

</Project>

Yeah, I noticed the NUnit 3.12.0 version. I updated to 3.13, and NUnit3TestAdapter to 4.0.0-beta.1 but it does not work too.

And guess what happens when I change the TargetFramework in project file to netcoreapp3.1?

NUnit Console Runner 3.12.0-dev-04990
Copyright (c) 2020 Charlie Poole, Rob Prouse
Friday, January 8, 2021 6:30:58 PM

Runtime Environment
   OS Version: Microsoft Windows 10.0.19042
  Runtime: .NET Core 3.1.10

Test Files
    .\NUnitConsoleBug.dll


Run Settings
    DisposeRunners: True
    WorkDirectory: C:\NUnitConsoleBug\bin\Debug\netcoreapp3.1
    NumberOfTestWorkers: 4

Test Run Summary
  Overall result: Passed
  Test Count: 1, Passed: 1, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2021-01-08 21:30:58Z
    End time: 2021-01-08 21:30:59Z
    Duration: 0.412 seconds

@CharliePoole
Copy link
Collaborator

If @ChrisMaddock, who wrote the .NET Core runner, jumps in here, you can just ignore me, since I'm focused on other areas. But here's what seems to be happening.

  1. There is no .NET 5.0 NUnit runner or engine, as I indicated earlier.
  2. If you had only .NET 5.0 installed, I suspect what you are doing would work because our 3.1 runner would execute under .NET 5.0 without any other option.
  3. You appear to have .NET Core 3.1 installed. (Right?) Consequently, dotnet selects that runtime to execute the runner, since the runner targets it.
  4. You have to tell dotnet (not the console) that you want to run under .NET 5.0.
  5. This is done using the dotnet command option -fx-version option.

Hope that's clear. I'm about 90% sure it's right 😕 because what you are doing is not exactly what we do in our own tests. We don't yet have a 5.0 build, so we are running 3.1 tests under 5.0. IOW, YMMV. 😄

@GitClickOk
Copy link
Author

GitClickOk commented Jan 8, 2021

Hey @CharliePoole, it works now! 😄

My problem was, I'm calling directly nunit3-console.exe or nunit (the global dotnet cli tool) in command line. With your tip about --fx-version (which appear works only using dotnet command directly), I executed this command:

dotnet --fx-version 5.0.1 "C:\Users\{Windows User}\.nuget\packages\nunit.consolerunner.netcore\3.12.0-dev-04990\tools\netcoreapp3.1\any\nunit3-console.dll" .\NUnitConsoleBug.dll

and the result is:

NUnit Console Runner 3.12.0-dev-04990
Copyright (c) 2020 Charlie Poole, Rob Prouse
Friday, January 8, 2021 7:43:04 PM

Runtime Environment
   OS Version: Microsoft Windows 10.0.19042
  Runtime: .NET 5.0.1-servicing.20575.16

Test Files
    .\NUnitConsoleBug.dll


Run Settings
    DisposeRunners: True
    WorkDirectory: C:\NUnitConsoleBug\bin\Debug\net5.0
    NumberOfTestWorkers: 4

Test Run Summary
  Overall result: Passed
  Test Count: 1, Passed: 1, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
  Start time: 2021-01-08 22:43:04Z
    End time: 2021-01-08 22:43:04Z
    Duration: 0.201 seconds

It correctly detected net5.0...

I think I can use it like this, but is this (or will be) the correct way to execute it from now on?

@CharliePoole
Copy link
Collaborator

As you saw, there are currently two runners, one for .NET Framework and another for .NET Core. I initially thought you might be using the wrong one, but you talked about running the dotnet command, so I figured you were not.

Having two runners is probably not a long term solution, because some folks will want to run projects that include both framework and core test assemblies. However, it's where we are right now.

If you want to try using a GUI, I invite you to look at my TestCentric GUI, which takes the approach of a single runner with multiple agents. Unfortunately, I haven't yet published a .NET 5.0 agent.

Both projects are looking at decoupling agents from the engine in the future, so they become pluggable.

@GitClickOk
Copy link
Author

GitClickOk commented Jan 8, 2021

This TestCentric GUI is amazing, but "unfortunatelly" 😄 you help me on fix my issue so my tests will be compiled and executed in .Net 5 now, and then this tool is obsolete for me. But really I will wait (or maybe help) on building your .Net 5 agent.

@CharliePoole
Copy link
Collaborator

Cute! Actually, creating a .net 5 agent is relatively trivial and has potential for wide benefits. I'll add an issue.

@CharliePoole
Copy link
Collaborator

FYI... the GUI now has a .NET 5.0 agent.

@anoftc
Copy link

anoftc commented Jan 14, 2021

I would like to point out that the suggested --fx-version parameter is only usable if you do not use the console runner directly. In our environment, we use unit tests via dotCover to measure code coverage too. So if I have

dotCover.exe cover /TargetWorkingDir=.\ /TargetExecutable="c:\Program Files\dotnet\dotnet.exe" /TargetArguments="test --logger trx;LogFileName=DotnetTestResults.xml" /Output=TestCoverageDotcover.xml /ReportType=XML

Then it works fine, I have a nice test output and a test coverage output as well because "dotnet test" will use the appropriate runtime, as it is shown during the execution: "Test run for c:\xxx\CarShop.Tests\bin\Debug\net5.0\CarShop.Tests.dll (.NETCoreApp,Version=v5.0)"

However, if I want to use the console runner directly, it does not work:

dotCover.exe cover /TargetWorkingDir=.\ /TargetExecutable="c:\xxx\nunit3-console.exe" /TargetArguments="\"c:\xxx\bin\Debug\net5.0\CarShop.Tests.dll\" --noc --skipnontestassemblies" /Output=TestCoverageDotcover.xml /ReportType=XML

In the second case, I cannot set the runtime version, nunit3-console will say: "Invalid argument: --fx-version"... As a result, I have failure:

Runtime Environment
   OS Version: Microsoft Windows 10.0.17763
  Runtime: .NET Core 3.1.11

Unable to load one or more of the requested types.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  ----> Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

In september we managed to switch to dotnet core with the test runners as you released the "NUnit Console and Engine 3.12.0 Beta 1" on 1/Aug. First of all, I'd like to say I am very thankful for that :) But now we'd like to switch to .net5.0 in February, but the standalone console runner does not work as expected...

Using "dotnet test" is a good workaround. And also, the .net5 tests are executed nicely with the latest TestCentricGui ZIP package ... So a question to @CharliePoole : what is the future plan with the runners?

  1. will you extend nunit3-runner with an --fx-version or implement some auto detection?
  2. will you extend TestCentricGui with some commandline switches to "execute tests, generate XML, then exit"?
  3. shall I forget the nUnit console runner, and just use "dotnet test" ?

(+1: btw, are there any advantages for the console runner over "dotnet test"? I see the XML report format is different, but is there any differences functionality-wise???)

ps> Thank you for your project!!!

@CharliePoole
Copy link
Collaborator

@anoftc First off, I can only try to answer questions about what NUnit3 Console now does. I'm not the guy to tell you what the plans are.

As far as your two command examples go, they are not comparable. The first doesn't run the console runner at all while the second does. In the second command, you have to pass the fx--version option to dotnet.exe, not to NUnit. You'll have to experiment to get the right ordering of options. Worst case, you may need to have two layers of dotnet.exe, one for cover and one for nunit. The second layer should use a run argument, not a test argument. (That said, I haven't tried this myself)

WRT your questions...

  1. Sorry, I'm not the guy to tell you what the console runner will do in the future. I'll leave that to @ChrisMaddock .

  2. The GUI can already do that. Ask on the GUI project for specifics, please.

  3. Personally, I don't think so. I use the console runner for all my command-line dotnet work. I just use dotnet run rather than dotnet test. Usually, it's all wrapped in a script anyway.

To your BTW question: Mainly, dotnet test relies on vstest, which has a general picture of tests that doesn't match NUnit's so well. For example, it doesn't know about warnings, inconclusive results, theories, explicit tests... so you have to know not to use any of those features when you use that runner. Not a criticism of the product, just a fact of life whenever you go through an adapter layer between two pieces of software, especially a generalized layer.

Charlie

@GitClickOk
Copy link
Author

@anoftc, this explanation from @CharliePoole is exactly what is happening with me.

  • Instead of detect the test dll version, the nunit3-console.exe uses .NET Core 3.1.10 instead of .Net 5;
  • I cannot use dotnet test because is very limited compared with nunit3-console.exe;
  • I call then dotnet to execute the nunit3-console.dll and as parameter I pass my test dll and other nunit parameters. The final command is something like this:
    dotnet --fx-version 5.0.1 "C:\path\to\nunit3-console.dll" C:\path\to\MyDotNet5Tests.dll

It works but it has disadvantages too. I successfully deployed to a "mcr.microsoft.com/dotnet/aspnet:5.0" container. Yesterday the code stopped to work in my computer. Guess what? I updated the Visual Studio version and it updated my .Net5 to 5.0.2, and how this code expects 5.0.1 it does not works anymore in my PC. And the worse part, --fx-version does not accept something like "5.0.*", so I will need revert (if possible) the version in my PC to match the server container or parametrize this, providing the correct framework version depending of the environment.

Or maybe nunit3-console.exe will be updated to deal with all this situation, what comes first 😄.

@oysteinkrog
Copy link

oysteinkrog commented Jun 10, 2021

I ran into this problem when updating our large WPF application to net5.0.
I was able fix the initial problem (could not load System.Runtime) by using latest myget build of NUnit.ConsoleRunner.NetCore and the "dotnet --fx-version ...." command described above.
Now I am facing a very similar problem:

Unable to load one or more of the requested types.
Could not load file or assembly 'WindowsBase, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Could not load file or assembly 'PresentationFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
  ----> Could not load file or assembly 'WindowsBase, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
  ----> Could not load file or assembly 'PresentationFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

Is this related to our test project targeting net5.0-windows instead of just plain net5.0?
Is there some way to configure the dotnet command to "run as net5.0-windows"?

@oysteinkrog
Copy link

@rprouse To me it seems like this is a blocking issue for using the nunit console runner with net5/net6.
Is there a plan for how this is supposed to work?
Should we transition away from using nunit and/or transition away from using the nunit console runner, if we want to upgrade to net5 and net6?

@rprouse
Copy link
Member

rprouse commented Jul 8, 2021

I think we need @ChrisMaddock's opinion on this since he did most of the work on the .NET Core version of the runner. I admit that the last minute changes in .NET 5 caught us off guard.

Until we get this fixed in the console runner, have you tried adding the NUnit VS Test Adapter to your projects and running using VSTest or dotnet test?

@nmuench
Copy link

nmuench commented Jul 20, 2021

@oysteinkrog You can run using the windows variant of .NET 5 by navigating to {YOUR_PATH}/.nuget\packages\nunit.consolerunner.netcore\3.12.0-beta2\tools\netcoreapp3.1\any\nunit3-console.runtimeconfig and changing it to
"runtimeOptions": { "tfm": "net5.0", "framework": { "name": "Microsoft.WindowsDesktop.App", "version": "5.0.0" } }
This should fix the issue you were having.

@oysteinkrog
Copy link

@nmuench Thank you, that does indeed work :)
Not the cleanest setup though; if we have to patch things like that in order for things to work.
I guess it might make sense to try to migrate to a more modern setup.

@CharliePoole
Copy link
Collaborator

This is straight-forward but slightly time-consuming because there are lots of moving parts.

Questions for @nunit/engine-team ...

  1. Do we want a .NET 5.0 agent?
  2. Should we do it as a part of 3.13?

My own answers...

  1. I believe we do. Some percentage of users need to run tests, which target .NET 5.0.
  2. Not 100% sure, but probably yes. Doing so will make our package structure even more complicated than it is. I'm in favor of simplifying a bit after 3.13, but I don't think it's that easy to do as a part of the release.

@CharliePoole
Copy link
Collaborator

OK... I did a spike.

TLDR; I'm not going to try this as part of the 3.13 release.

The reason I thought it would be fairly straightforward is that I already run a .NET 5.0 agent in the testcentric fork of the engine. However, in that agent, there are other significant changes underlying the change, which are not present in the NUnit engine.

I think we should talk about this in planning for future development, after the 3.13 release.

@mikkelbu
Copy link
Member

Answers to the questions

  1. I also think so
  2. Given the complications I think it is sensible to leave this out of the release

@CharliePoole
Copy link
Collaborator

NOTE to self... I need to detail just what the "underlying changes" are required.

@CharliePoole
Copy link
Collaborator

CharliePoole commented Jan 1, 2022

Both the netfx and net core runners are discussed here but that's primarily due to my confusion. The original issue pertained to the net core runner, so I'm labeling it accordingly.

Adding a .NET 5.0 agent to NUnit.ConsoleRunner.NetCore would be one BIG enhancement, since the .Net Core runner does not currently support agents at all!

We could consider adding a .NET 5.0 build, however. If I understand correctly, a .NET Core tool can have multiple builds of the exe included.

@nunit/engine-team Let's discuss this.

@mikkelbu
Copy link
Member

mikkelbu commented Jan 1, 2022

We could consider adding a .NET 5.0 build, however. If I understand correctly, a .NET Core tool can have multiple builds of the exe included.

The usual disclaimer :): I don't know anything about dot net core tools, but if we should add a .NET 5 target, then we should also add a .NET 6 target. I tried to google for information about multiple builds of the exe, but I'm didn't find anything useful.

@jnm2
Copy link
Collaborator

jnm2 commented Jan 3, 2022

I wonder if adding net5.0 and net6.0 builds of the runner might cause all netcoreapp3.1 tests to start running under .NET 5 or 6, whatever is available on the machine. Would there be any way for a user of the tool to control this?

If this isn't the path forward, then agents seem to be. Maybe instead of making the NetCore package be able to run agents, we make the NUnit.ConsoleRunner package able to run .NET Core 3.1/5/6 agents?

@CharliePoole
Copy link
Collaborator

@jnm2 I sent you a separate note about a problem I'm having with the .NET 5.0 Agent in the Azure Linux job. But the good news is that it works everywhere else.

This agent approach is what I was pushing for originally. I felt that the NetCore runner wasn't the right way to go. However, since some people can only run under .NET Core it appears we need both approaches.

@CharliePoole
Copy link
Collaborator

Comments on this issue are pretty cluttered, in large part because I tried to help without understanding that the current NETCORE console runner doesn't use agents at all! Everything is run in process.

Now I'm involved with both runners - NETFX and NETCORE - so I'd like to start over and try to eliminate the confusion... including any that my earlier comments may have caused. So I'm closing this issue and creating a new one to replace it.

Before doing that, I'll summarize where we are on this issue...

  1. The NETCORE console runner is (unfortunately) called nunit3-console just like the NETFX runner, but it has entirely different capabilities.

  2. The NETCORE runner does not launch agent processes to isolate tests but runs them in-process.

  3. The NETCORE runner has some support for engine extensions, but of course only for extensions, which target .NET Core or .NET Standard. I only know of one such extension... our V2 Result Writer. All our other extensions are NETFX only.

  4. The NETCORE runner itself targets .NET Core 3.1 and is set up to allow rollover to new major versions if 3.1 is not installed. That means the tests it runs have to target .NET Core 3.1 or lower.

  5. Since there is no VS project loader extension compatible with .NET Core, the NETCORE runner can only run assemblies entered at the command-line.

@nunit/engine-team Please correct me if you think any of the above points is wrong!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement NetCoreRunner Issue related to the .NET Core console runner
Projects
None yet
Development

No branches or pull requests

8 participants