How to run NUnit 2 tests in visual studio 2022 - visual-studio

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.

Related

How to Configure Specflow 3.0.199 with NUnit 3.11?

I have done this a couple of times before, but it's not working today. Am I missing something?
I want to configure Specflow from the scract, using NUnit and to execute inside Visual Studio.
I've seen many tutorials but they are not working to me :P. I'm trying to use the latest versions.
These are the steps I'm doing on Visual Studio 2017:
Create a test project (.NET Framework)
Install Specflow plugin for Visual Studio (Tools > Extensions and Updates)
Delete reference of MSTests from the nuget packages.
Install SpecFlow 3.0.199
Install NUnit 3.11
Install SpecRun.Runner 3.0.284
After creating a default feature file and generate its steps, when I compile the solution I get this error on CalculatorFeature.feature.cs (the generated file):
It's like those configurations are not compatible. What's going on?
If you have another step by step list, let me know how to configure Specflow with NUnit to run on Visual Studio 2017, please.
For SpecFlow 3 you have to use the MSBuild generation.
To this, follow these two steps:
Add the NuGet package SpecFlow.Tools.MsBuild.Generation with the same version as SpecFlow to your project
Remove all SpecFlowSingleFileGenerator custom tool entries from your feature files.
From https://specflow.org/2019/generating-code-behind-files-using-msbuild/
Background what is happening:
The VS Extension has sometimes problems to find the used SpecFlow version. In that case, it falls back to the SpecFlow version shipped with the extension (which is really old). This version is generating code with now not existing NUnit attributes.
TestFixtureSetUp and TestFixtureTearDown attributes were deprecated for quite some time and were finally removed. They are replaced by OneTimeSetUp and OneTimeTearDown.
Your choices are probably...
Go back to an NUnit version that supports the old attributes.
Get a version of SpecFlow that uses the new attributes.
Find a way to configure SpecFlow and tell it to use the new attributes. Sorry, but this option, which is no doubt the best, is out of my wheelhouse.

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.

How to create custom test case in TestWindow in VS2015

How I can create custom test case in VSIX extension for Visual Studio 2015?
In older version of Visual Studio I was using namespaces
Microsoft.VisualStudio.TestPlatform
Microsoft.VisualStudio.TestWindow
Microsoft.VisualStudio.TestWindow.Core
Microsoft.VisualStudio.TestWindow.Interfaces
but these namespaces are in VS2015 (Community) unavailable. Is there any alternatives to create custom test cases parsed from my specific format in VSIX extension?
In recent versions of Visual Studio (2012 and later), they added native support for custom test engines. To write one you would use the following interfaces (which have no documentation to speak of) in the Microsoft.VisualStudio.TestPlatform.ObjectModel namespace:
ITestContainer – Represents a file that contains tests
ITestContainerDiscoverer – Finds all files that contain tests
ITestDiscoverer – Finds all tests within a test container
ITestExecutor – Runs the tests found inside the test container
More Information:
There are some tutorials(1)(2) that give step-by-step instructions and example code that use the APIs mentioned above. Due to the involved nature, I'm not going to repost the entire tutorials here. Note, while the posts were originally written against 2012RC, they are still valid for 2012 RTM, 2013, and 2015.

Can't debug NUnit tests with Visual Studio

Trying to debug an NUnit test in VS2010 and is not stopping on the breakpoint. It was working the last time I tried need to debug the test (maybe 1 yr ago) but now it doesn't work.
I've tried the following:
How to debug with vs.net 2008 and nunit?
http://erraticdev.blogspot.com/2012/01/running-or-debugging-nunit-tests-from.html
I've tried attaching, rechecking my installation, updated the config file so it's using the 4.0 runtime, still doesn't hit the breakpoint.
What am I missing?
You can debug nunit tests in VS studio community version only. For this you need to install Nunit3testAdpter. You can add this in Tools -> Extension and updates. or from Nuget packages.
This is a long overdue question but I haven't seen the solution to debug NUnit tests directly within Visual Studio. This is quite easily possible and without any third party tools. All you have to do is configure your test project (which is just a plain old Class library project) so it will start NUnit test runner whenever you hit F5 or Ctrl-F5 (just run, no debugging).
Particularly you will have to configure your project properties to start an external program:
Step by step configuration is very well described in this blog post. It advises you to use NuGet to obtain NUnit test runner and configure project to execute the runner when you try running your library project. As simple as that. Using no specific tools which are usually not free.
There are multiple reasons why this may happen. If your application's target framework is different from NUnit's, then you won't be able to debug, because the tests are actually being run by nunit-agent.exe.
For me, my application was using 4.5, but NUnit's was using 3.5. (You can find this from one of the NUnit GUI applications -> Help -> About)
To fix this, change the nunit.exe.config file to include the following, inside the configuration section:
<startup>
<requiredRuntime version="4.0.30319" />
</startup>
This can also happen when your PDB generation is set to embedded. Switching it to full will allow the nunit test adapter to start with the debugger attached. At that point it can be switched back to embedded and it will debug again.
The setting is on the project properties pages, in the Build tab, then click the Advanced button. I always choose "All Configurations" at the top, so I make sure I'm emitting a useful PDB (or embedding the info) when building Release configuration assemblies too.
The other day I failed to hit a breakpoint in my NUnit debugging. It took me a while to realize that someone had copy/pasted the test into a different file and I was running a different test than the one that the breakpoint was in.
I recently had a similar problem. Changing the project's platform to AnyCPU solved it for me. Also worth checking:
1) Check NUnit's latest version (I was using 2.5.7, updated to 2.6.2)
2) The Target Framework for your test project. I was using .NET 4.0 (you can find it under Properties -> Application, on VS2010)
At least up to vs2010 the debugger can only debug 32 bit apps but not 64 bit apps.
With vs2010 I am using a 32bit nunit.exe version and use "attach to debugger". This workes well for me.
Please upgrade NUnit Test Extension and close the Visual studio so Visx (probably spell) will run and update NUnit tool.
After this you can open your project and run NUnit test project.
It will run.
I tested accurately.
Try changing the test to x64. From the menu do
Test -> Test Settings -> Default Processor Architecture -> x64.
i think u cant debug with Visual studio. better u install TestDriven.NET.
then
Put the BreakPoint on the test method
Right click on the test
method.
select TestWith->Debugger

Logging VS2010 unit test results in TFS 2008 not working

The tests appear to run fine after compliation, but the results don't go anywhere. A .trx file is written and indicates all tests passing. Team Build thinks no tests have been executed and gives the dreaded "Partial Success" result. I suspect that TFS cannot publish the trx to the database for some reason...possibly because the VS2010 version of the test results is not backwards compatible with TFS 2008...?
I'm running the build with MSBUILD 4.0 and using version 10 of MSTEST.
I've read that using the previous version of MSTEST (version 9 with VS 2008) could help. I tried this...MSTEST rightly complained that the test assembly was built against a more recent version of the .NET framework.
Anyone else had success with this? What should I try next?
Turns out I didn't have the right Microsoft.TeamSystem assemblies in the GAC. The version 9 assemblies were there but not version 10. This likely is due to VS2010 being uninstalled / reinstalled out of order w/ VS2008 (or something, who knows). A "Repair Installation" setup step solved the problem.
So, it looks like MSTEST 10 can indeed post results to a TFS 2008 datastore. Wee!

Resources