nUnit 3 on Visual Studio Community 2019 - visual-studio

can anyone help me on running unit tests with nUnit on Visual Studio 2019? I've referenced nUnit3 and nUnit3TestAdapter on my project, so far so good, but when I try to run the tests, the output returns the following message:
========== Build: 0 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========
It looks like has something outdated, but all references here are both NuGet packages above, someone knows how to fix it? It's a simples calculator to study TDD.

I had the same issue. I did a few things at once, but I think what solved the issue for me was restarting Visual Studio, and deleting the Main function.

You should paste your Output after build Tests because there should be information, why it doesn't work.
If you use .NET Core project you should get library - Microsoft.NET.Test.Sdk. If this doesn't help check the dependencies between your TestAdapter and NUnit3.

You could try installing the Visual Studio Test Adapter extension on your VS. Simply download it from the marketplace and install, and try running your tests once more.
https://docs.nunit.org/articles/vs-test-adapter/Index.html
If it doesn't work - do provide more info regarding the output from Tests (there is a drop-down where you can select from where you want to read the output).
Also, provide versions of NUnit and NUnit adapter packages you're using as well as what's the project type - .net core OR .net framework.

Related

How to run NUnit 2 tests in visual studio 2022

I am trying to execute NUnit tests on a legacy project in Visual Studio 2022 professional. Migrating from NUnit 2 to NUnit 3 is not yet an option, and part of the team works with Visual Studio 2019. The problem I am facing is that the tests are not executed by VS 2022, without any error message on the attempt.
The test explorer displays the following after executing the test (and the console output finishes with a successful build):
The NuGet Package manager had NUnit 2.6.1 already installed. I additionally installed the packets NUnit.Extension.NUnitV2Driver and NUnit.Extension.NUnitV2ResultWriter. A test adapter seems only available for NUnit3 (NUnit3TestAdapter, which I also installed). I enabled all the packages for the individual project as was commented in this question. Is there anything else to install/configure that I could be missing to make this work?
Just a few suggested approaches...
The NUnit3TestAdapter, as the name indicates, is designed for NUnit 3. While it is able to run NUnit3 tests by use of the NUnitV2Driver extension, I don't think that will work under Visual Studio just by installing the package. You could experiment by modifying the .addins file installed along with the the adapter, but I can't give you precise instructions as I haven't tried it.
BTW, the V2 driver extension produces output in V3 format, which is probably what you want for use under Visual Studio. The V2 result writer is only needed if you have a reason to want an output file in V2 format.
I think your best bet may be to try using the last release of the NUnitTestAdapter (i.e. without '3' in the name), which only works with NUnit V2. If it will load under VS2022, it should do exactly what you want. In that case, you should stop loading the two extensions, which the V2 runner doesn't support.

XUnit Tests No Longer Working After Upgrade From .NET 5 To .NET 6 (Q & A)

I have an xUnit unit testing project. All was working fine in .NET 5.
In Visual Studio 2022, I changed the .NET Version in the csproj to .NET 6 as shown below.
Following this, the tests build but no longer run.
There is no info in the output window. The Test Explorer just says it wont run the tests, with 'unexpected error detected'.
What should I do to fix this?
I created a new project and compared the csproj file with my old project. There were a couple of differences
First, I needed to add the nuget package for Microsoft.NET.Test.Sdk (in my case, version 16.11.0). This seemed to fix it.
I also noticed a couple of properties in the first PropertyGroup that I was missing. I added those too. However, just adding Microsoft.NET.Test.Sdk fixed it for me.
In my case I was changing from NUnit to XUnit and also needed to add the xunit.runner.visualstudio nuget package

Resharper shows all tests as inconclusive and has error "testadapter.dll does not exist on disk"

I created a new dot net core unit test project in Visual Studio using Visual Studio 2017. It uses NUnit 3. When I run the tests all of them show as "Inconclusive: Test not run".
Additionally, the Resharper test runner shows an error: "testadapter.dll does not exist on disk".
I needed to install the NUnit3TestAdapter Nuget package.
Looking back, this seems like it should have been obvious to me. I was surprised that searching for the error message did not point towards the solution.
Less obvious was the fact that I had to install the Microsoft.NET.Test.Sdk Nuget package.

NUnit VS Adapter do not discover tests due to FileNotFoundException, Exception converting tests

When trying to run tests via Visual Studio Test Explorer, I got following error for all tests in solution (those that use Typemock and those that don't):
[2/12/2018 11:35:36 AM Informational] NUnit VS Adapter 2.1.1.0 discovering tests is started
[2/12/2018 11:35:37 AM Error] Exception System.IO.FileNotFoundException, Exception converting Manager.Tests.MessageLoggerTest.AddMessage_WhenAddMessageIsCalled_ThenAddMessagesToList
...
I found only one mention of the problem online on Xamarin forum, but with no fix (https://forums.xamarin.com/discussion/119513/xamarin-ui-tests-filenotfoundexception).
I use Visual Studio Enterprise 2017, version 15.5.6, NUnit 2.6.4, NUnitTestAdapter 2.1.1 and Typemock 8.6.0.22.
Running tests via Typemock runner (Test Navigator) works as expected.
EDIT
I feel a bit embarrassed, I cannot reproduce my original error. At work, we use multiple branches of the code base. Now, one branch works fine. I can discover and run tests via VS runner (Test Explorer).
On the other branch, when rebuild 1. test project I am getting StackOverflowException instead of FileNotFoundException. But it also discovers 41 of 43 tests that are in project. The 2. test project get also StackOverflowException and discovers none of 295 tests.
[2/20/2018 10:43:40 AM Informational] ------ Discover test started ------
[2/20/2018 10:43:44 AM Informational] NUnit VS Adapter 2.1.1.0 discovering tests is started
[2/20/2018 10:43:54 AM Error] The active test discovery was aborted. Reason: Process is terminated due to StackOverflowException.
[2/20/2018 10:43:54 AM Informational] ========== Discover test finished: 41 found (0:00:13.8969695) ==========
Have compared solution file, project files and NuGet package configs. Only difference between the branches was packages.config line:
<package id="Typemock.Isolator" version="8.6.0.18" targetFramework="net452" />
The working branch have targetFramework="net452", failing branch had targetFramework="net462". However changing framework to net452 didn't help.
Will have to dig deeper to see, what makes the difference. Thanks for anyone's help and time.
Try installing the NUnit 2 Test Adapter extension for Visual Studio from the gallery. This fixed the issue for me on a project also using NUnit 2.6.4.
I have faced the same issue.
In my case deleting temporary files in windows solved my issue.
Close visual studio. Go to Run and type %temp%. Clear all the files. Now the visual studio
will discover all the UI test case.

Visual Studio FsUnit test setup - Exception NUnit.Engine.NUnitEngineException

I am using Visual Studio 2013, installed FsUnit 2.2.0, which requires NUnit 3.2.1 and FSharpCore 3.1. I created a separate test project and put a testfixture and test in there. My platform is x64 Win 10. The config is for 'AnyCPU' and 'Debug'. I've tried test settings for x86 and x64. When trying to build and create tests, I get:
------ Discover test started ------
NUnit Adapter 3.2.0.0: Test discovery starting
Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in C:\Users\Dad\Documents\Visual Studio 2013\Projects\...
Cannot run tests in process - a 32 bit process is required.
Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in C:\Users\Dad\Documents\Visual Studio 2013\Projects\...
Cannot run tests in process - a 32 bit process is required.
NUnit Adapter 3.2.0.0: Test discovery complete
========== Discover test finished: 0 found (0:00:00.1230077) ==========
If I change the config for both the test and target projects to 'x86' (instead of AnyCPU) then the error for the base project goes away, but the same thing happens for the test project.
No tests are ever discovered, help please ... and many thanks!
You will need to remove nunit from your solution and install it again with "NUnit3TestAdapter", version 3.0.10 works.
Uninstall any NUnit software in add/remove program and in your solutions. Now using Nuget package manager (tools > NuGet Package Manager > Manage NuGet Packages for solution...) remove any NUnit you have in a solution and install older version (e.g. 3.0.1). Find "NUnit3TestAdapter" and install in version 3.0.10.
I had the same problem with my .NET Core 2.0 project with NUnit 3.9 in Visual Studio 2017 and tests were not showing up in TestExplorer. Was stuck with this for quite some time. None of the solutions suggested in other related questions worked.
Then I figured out from this link that a class library with target .NET Standard does not work. The test project has to target .NET Core. Also, Microsoft.NET.Test.Sdk NuGet is required.
So, the steps are
Make sure that the test project targets .NET Core
Install latest NUnit NuGet (I used 3.9)
Install corresponding NUnitAdapter NuGet (I used NUnit3Adapter)
Install Microsoft.NET.Test.Sdk NuGet
Re-build and your tests will appear in Test Explorer in Visual Studio.
Note: Already added this answer to another .NET Core specific question. Adding here too, as the solution might be helpful in this scenario as well.
There is an error in NUnit 3.2.1 whereby the TestEngine assumes that it can't run a test requiring 32-bit execution in process. The assumption is always valid for NUnit's own runners, but not necessarily when the process is started by some other program. There's an issue filed about this.

Resources