I am trying to run my NUnit tests built with .Net 7 in Jenkins. They run perfectly fine locally in my Visual Studio. I can't get them to run on my Windows machine my Jenkins Agent is running on since upgrading from .net framework 4.X to .Net 7.0.
I took Jenkins out of the picture and tried to invoke the tests directly with dotnet test
with no luck.
I have the 32 and 64 bit versions of the .Net 7.0 framework installed. Dotnet test is recognized as a command. Specifying the framework in the command doesn't seem to make a difference. Specifying x86 as the architecture makes it fail completely even when I specifically point to the x86 version of the framework. dotnet test is pointing at the 64bit version.
My Command to run the tests:
c:\Jenkins\workspace\Automation_Solution_Build\Project\obj\Debug\net7.0>dotnet test TestDll.dll /TestAdapterPath:C:\Users\username\.nuget\packages\nunit.consolerunner\3.16.0\tools\nunit-console.exe --framework:net7.0 --filter:TestCategory=TestCategory
This results in the following message:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in c:\Jenkins\workspace\Automation_Solution_Build\Project\obj\Debug\net7.0\TestDll.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
I removed the filter entirely just to make sure it wasn't failing the category for some reason and it still didn't work. It can't seem to see the tests in the dll.
I then tried using dotnet vstest
instead and even with no filter I received the same exact error.
Any guidance is appreciated.
It turns out I was using the wrong folder for the DLL. When you pass the
--framework
option it is only specifying the type of the framework. It has to get the actual framework to be used from the runtimeconfig.json file that is generated at build time.Here is some information on that. https://learn.microsoft.com/en-us/dotnet/core/runtime-config/#runtimeconfigjson
This file doesn't exist in the obj directory. It is in the bin directory. So I needed to look in the bin directory for my project and execute the command and it worked.
The
--verbosity
switch can be removed to push less junk to the console.https://learn.microsoft.com/en-ca/dotnet/core/tools/dotnet-test?tabs=netcore2x