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?
1 answer
-
answered 2022-05-05 14:03
Charlie
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.
do you know?
how many words do you know
See also questions close to this topic
-
Can't clone from repository of Github in Visual Studio
Recently, my visual studio can't clone from repository of GitHub.
Once it is completed clone, the visual studio will report this error "One or more errors occurred":
I cannot find any error in the output windows in visual studio.
And then, the Git Changes is blank. I can't pull and push any.
Previously I considered maybe it is the problem of my Visual Studio or Operation System.
However, after I reinstalled my Visual Studio and even reinstalled my Operation System, the problem is still here.
Soon I found a topic may relate my problem:Git has stopped working after installing VS 2022
Whereas, I tried all the ways in it and it doesn't work any.
The version of my Visual Studio is 2022 17.1.6. What's wrong with it?
-
How can I add intel Fortran compiler after installed intel oneAPI and visual studio?
I installed visual studio 2022 Community. Also, I installed Intel® oneAPI Base Toolkit and Intel® oneAPI HPC Toolkit. However, I do not know how to configure fortran compiler into visual studio so I can make Fortran project. Can you please help me with this?
-
School Project, set up OpenGL on VS 2019 Community
I am trying to set up OpenGL on my PC for a project. The project gave me sample code to run and a folder to add include directories and libs to my sample code solution in VS 2019 community. The directions were awful and wanted me to upload the include and lib directories to VC++. This did not work even remotely, none of the glfw or glew headers were recognized. I found other directions online to upload the include folders under C/C++>General>Additional Include Directories and the libs under Link>General>Additional Lib Directories. Then I added glfw3.lib;glu32.lib;glew32.lib;opengl32.lib to my Link>Input>Additional Dependencies. This allowed my program to compile. But now I get the following errors plus 90 more like it:
Warning LNK4098 defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library OpenGLSample C:\OpenGL_Projects\OpenGLSample\OpenGLSample\LINK 1 Error LNK2019 unresolved external symbol __imp__TranslateMessage@4 referenced in function __glfwPlatformInit OpenGLSample C:\OpenGL_Projects\OpenGLSample\OpenGLSample\glfw3.lib(win32_init.obj) 1```
-
NUnit Test case
using System; using System.Collections.Generic ; using System.Linq; using System. Text; using System. Threading. Tasks; namespace DemoAppCore{ public class Program { public static Enployee e1 = null; public static Employee EnrollEmployee() { return new Employee(){Name="Tom", Id="A1234" }; } } public class Employee { public string Name { get; set; } public string Id { get; set; } }
Please anyone help me to write a C# NUnit Test case for this program.I tried many different way to solve this program but none of the test cases work. Class Program This class contains a method, 'EnrollEmployee' In this method, an object for "Employee" is created and returned.
Class Employee This is a model class containing Name and Id property.
Write respective test methods for the following : a) Variable "e1" is null b) On invoking method 'EnrollEmployee', the object returned is not null. c) The "Name" property is equal to "Tom" by invoking method 'EnrollEmployee' d) The "Id" property is equal to "A1234" by invoking method 'EnrollEmployee'
Implement:
- Add the required test attribute for the class FunctionalTest
- Add the required test attribute for each test methods
- Wherever applicable, Assert whether the actual is equal to the expected
-
Running Playwright dotnet tests on Azure DevOps
I'm trying to execute Playwright dotnet tests with Nunit framework on Azure DevOps. I'm unable to execute testcases as and when I try to install playwright as a part of pipeline, there is an error thrown and build gets failed with the following message
Couldn't find project using Playwright. Ensure a project or a solution exists in D:\a\1\s, or provide another path using -p. Below is my azure pipeline steps, Can someone please help me where exactly the issue is and I have tried both Windows and latest Ubuntu agents
# ASP.NET Core (.NET Framework) # Build and test ASP.NET Core projects targeting the full .NET Framework. # Add steps that publish symbols, save build artifacts, and more: # https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core trigger: - master pool: vmImage: 'windows-latest' variables: solution: '**/*.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release' steps: - task: UseDotNet@2 displayName: 'Install .NET' inputs: packageType: 'sdk' version: '6.0.x' installationPath: $(Agent.ToolsDirectory)/dotnet includePreviewVersions: true - task: DotNetCoreCLI@2 inputs: command: 'build' projects: '**/*.csproj' - task: DotNetCoreCLI@2 inputs: command: 'custom' custom: 'new' arguments: 'tool-manifest' - task: DotNetCoreCLI@2 displayName: 'Installing Playwright Cli' inputs: command: 'custom' custom: 'tool' arguments: 'install Microsoft.Playwright.CLI' - task: DotNetCoreCLI@2 displayName: 'Building tests project' inputs: command: 'build' projects: '**/*Tests*.csproj' - task: DotNetCoreCLI@2 displayName: Run Playwright Install inputs: command: custom custom: 'tool ' arguments: run playwright install - task: DotNetCoreCLI@2 displayName: 'Run tests' inputs: command: 'test' projects: '**/*Tests*.csproj' testRunTitle: 'new pipeline'
-
Instantiation of User Controls dissapearing on InitalizeComponent() when modifiyng Form
Hi everyone and thank you in advance. I have created a User Control named PanelOption that is a panel with a CheckBox and a TextBox, and these are inside a FlowPanelLayOut. It runs well and everything works perfectly.
The problem comes when I modify the form where these PanelOption are. They dissapear from the InitializeComponent method as I show you below:
private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CrearMultipleForm)); this.txtEnunciado = new System.Windows.Forms.TextBox(); this.txtPuntaje = new System.Windows.Forms.TextBox(); this.lblPuntaje = new System.Windows.Forms.Label(); this.lbNumPreg = new System.Windows.Forms.Label(); this.FlowPanelOpciones = new System.Windows.Forms.FlowLayoutPanel(); this.panelOptionSM1 = new Custom_Components.PanelOption('A'); this.panelOptionSM2 = new Custom_Components.PanelOption('C'); this.panelOptionSM3 = new Custom_Components.PanelOption('B'); this.panelOptionSM4 = new Custom_Components.PanelOption('D'); this.panel2 = new System.Windows.Forms.Panel(); this.botonMinus = new QuizifyIU.Controles_Personalizados.Boton(); this.botonPlus = new QuizifyIU.Controles_Personalizados.Boton(); this.btnCrear = new QuizifyIU.Controles_Personalizados.Boton(); this.btnCancelar = new QuizifyIU.Controles_Personalizados.Boton(); this.btnRespAbierta = new QuizifyIU.Controles_Personalizados.Boton(); this.btnVF = new QuizifyIU.Controles_Personalizados.Boton(); this.btnMultiple = new QuizifyIU.Controles_Personalizados.Boton(); this.flowLayoutPanel1.SuspendLayout(); this.panel1.SuspendLayout(); this.FlowPanelOpciones.SuspendLayout(); this.panel2.SuspendLayout(); this.SuspendLayout();
Here you can see the objects panelOptionSM1, panelOptionSM2... being instantiated . But as I said when I modify the form on the designer, Visual Studio removes the instantiation of the objects like this:
private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CrearMultipleForm)); this.txtEnunciado = new System.Windows.Forms.TextBox(); this.txtPuntaje = new System.Windows.Forms.TextBox(); this.lblPuntaje = new System.Windows.Forms.Label(); this.lbNumPreg = new System.Windows.Forms.Label(); this.FlowPanelOpciones = new System.Windows.Forms.FlowLayoutPanel(); this.panel2 = new System.Windows.Forms.Panel(); this.botonMinus = new QuizifyIU.Controles_Personalizados.Boton(); this.botonPlus = new QuizifyIU.Controles_Personalizados.Boton(); this.btnCrear = new QuizifyIU.Controles_Personalizados.Boton(); this.btnCancelar = new QuizifyIU.Controles_Personalizados.Boton(); this.btnRespAbierta = new QuizifyIU.Controles_Personalizados.Boton(); this.btnVF = new QuizifyIU.Controles_Personalizados.Boton(); this.btnMultiple = new QuizifyIU.Controles_Personalizados.Boton(); this.flowLayoutPanel1.SuspendLayout(); this.panel1.SuspendLayout(); this.FlowPanelOpciones.SuspendLayout(); this.panel2.SuspendLayout(); this.SuspendLayout();
The funny part is that the rest of the code concerning these objects remains untouched regardless of modifying the form. The rest of the code I am refereing:
// panelOpcionSM1 // this.panelOptionSM1.BackColor = System.Drawing.Color.Transparent; this.panelOptionSM1.Location = new System.Drawing.Point(3, 3); this.panelOptionSM1.Name = "panelOpcionSM1"; this.panelOptionSM1.Size = new System.Drawing.Size(520, 48); this.panelOptionSM1.TabIndex = 110; // // panelOpcionSM4 // this.panelOptionSM4.BackColor = System.Drawing.Color.Transparent; this.panelOptionSM4.Location = new System.Drawing.Point(3, 57); this.panelOptionSM4.Name = "panelOpcionSM4"; this.panelOptionSM4.Size = new System.Drawing.Size(520, 48); this.panelOptionSM4.TabIndex = 112; // // panelOpcionSM2 // this.panelOptionSM2.BackColor = System.Drawing.Color.Transparent; this.panelOptionSM2.Location = new System.Drawing.Point(3, 111); this.panelOptionSM2.Name = "panelOpcionSM2"; this.panelOptionSM2.Size = new System.Drawing.Size(520, 48); this.panelOptionSM2.TabIndex = 111; // // panelOpcionSM3 // this.panelOptionSM3.BackColor = System.Drawing.Color.Transparent; this.panelOptionSM3.Location = new System.Drawing.Point(3, 165); this.panelOptionSM3.Name = "panelOpcionSM3"; this.panelOptionSM3.Size = new System.Drawing.Size(525, 48); this.panelOptionSM3.TabIndex = 109;
And also:
private Custom_Components.PanelOption panelOptionSM3; private Custom_Components.PanelOption panelOptionSM1; private Custom_Components.PanelOption panelOptionSM4; private Custom_Components.PanelOption panelOptionSM2;
This only happens when I modify the form, not when I rebuild the solution or change the code of the form.
-
Create XML documentation file in VS 2022:s User Interface
Goal:
Create XML documentation file with VS 2022 as the same in the picture below. The XML should be used for Swagger.Problem:
It works in 2019 but I cannot find the same functionality in VS 2022?Other info:
In VS 2019 you do this in order to create XML documentation file (https://code-maze.com/swagger-ui-asp-net-core-web-api/) -
Porting Xamarin tutorial over to .NET MAUI
For my first ever mobile app project (which will eventually become an actual commercial project), I would like to try out .NET MAUI. Unfortunately since it's still in pre-release, there is scarce documentation and no tutorial projects for it. I did find the Xamarin tutorial here:
https://dotnet.microsoft.com/en-us/learn/xamarin/hello-world-tutorial/intro
... but I don't think it's compatible with .NET MAUI.
Are there any other places where a newbie mobile developer who knows Visual Studio and C# can see an example app and be able to learn through creating an app on the level of, say, the Contoso University web app I went through to learn ASP.NET Core with data model? Can a Xamarin tutorial be tweaked to work with .NET MAUI? If so, I would be happy to help with that process. Now that I think about it, since I developed my web site based on the Contoso model, maybe I could help create a mobile app in .NET MAUI for that Contoso project? Anyone at Microsoft interested?
-
Why is NUnit ignoring tests with Combinatorial/Values attributes?
I tried to use
Combinatorial
/Values
attributes in NUnit.While it works locally, the test decorated with those attributes are skipped in TeamCity build running NUnit 2.6.2—the build report indicates that the test was ignored, without giving any details about the reason to ignore it.
According to the documentation,
Combinatorial
attribute (as well as theValues
attribute) exists in NUnit 2.5, and so I would expect it to still be supported in NUnit 2.6.Why is the test ignored?
Here's a most basic example which reproduces the issue. Locally, both tests run and give the exact same results. On TeamCity, only
Test1
is executed, andTest2
is marked as ignored.[TestCase("a", "1")] [TestCase("a", "2")] [TestCase("b", "1")] [TestCase("b", "2")] public void Test1(string x, string y) { Assert.AreEqual(x + "," + y, string.Format("{0},{1}", x, y)); } [Test, Combinatorial] public void Test2([Values("a", "b")] string x, [Values("1", "2")] string y) { Assert.AreEqual(x + "," + y, string.Format("{0},{1}", x, y)); }
-
How to re-run a fail Nunit Test 2.6.2
I am trying to Re-run failed Nunit tests, mainly because of flackiness with selenium.
[TearDown] public virtual void TearDown() { var testName = TestContext.CurrentContext.Test.FullName.Replace("Server.Tests.", string.Empty); if (TestContext.CurrentContext.Result.Status == TestStatus.Passed) return; else if (_testFailure < 3) { _testFailure++; Console.WriteLine($"\n {testName} {TestContext.CurrentContext.Result.Status}... Retrying attempt {_testFailure}"); DbReloader.LoadUnitTestData(DbFactory); TestExecutionContext.CurrentContext.CurrentTest.Run(new NullListener(), TestFilter.Empty); } BrowserDriver.GetScreenshot() .SaveAsFile($"{testName}.fail.png", ImageFormat.Png); }
The problem is after the test runs again, it will continue with the tear down of the test as the original test failed. How do I override the TestContext.CurrentContext.Result with my retried test results?
-
nunit 3 tests on command line as nunit 2.6.4
I have the following Nunit 3 command running in a console window.
sh "#{NUNIT}" \ ' Build\bin\Testing\Functional\Functional.dll --test=Functional.Features.Customer.Account.NotificationDetailsFeature.Register'
I need to be able to do this with Nunit 2.6.4. NUnit 2.6.4 doesn't have the
test
flag available. How can I specify a given test in NUnit 2.6.4?