I can see both test projects from the NUnit Gui (loaded separately) but I can not see both projects from the Visual Studio Test View. The Test View only shows the first/original project. Hitting reload doesn't do anything. How do I get the Test View to display the second/later project? It should show both at the same time/same view, yes?
If I can only see one project's test in the Test View by design, how do I get the Test View to change projects?
Details:
I created the second project by hand ie not "create a test" as a project library with the nunit.framework.dll referenced. I checked the assembly files of the two projects as well as the properties and they look the same.
I'm on VS 2010 Professional using NUnit 2.6.0.12051 with "Visual NUnit 2010" version 1.2.4 extension installed.
I have one NUnit test project that is working both in VS Test View and NUnit Gui. I added a second project with a [TestFixture] class and a [Test] method. All projects build sucessfully. Both tests refer to the nunit.framework.dll in a parent directory to both.
There is a tag in the project file describing a project as a test project.
In the PropertyGroup section of the csprj file, add this:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
See more details here:
http://www.kindblad.com/2010/08/07/how-to-change-an-existing-visual-studio-project-into-a-test-project
There are many problems that can cause this. Here's what mine was:
I had 2 NUnit test projects.
"Test Explorer" -> "Run All" would only find tests from one project.
Explicitly right clicking on one of the tests that wasn't found and clicking "Run Test" resulted in "No tests found." in the Output window.
All projects on all configurations were set to Any CPU, but it didn't matter if X86 was chosen for everything either.
The problem was that my Visual Studio (2015, FWIW) was using Test Adapter 2.x, and one of my projects had pulled NUnit 3.0 using NuGet. Test Adapter 2.x doesn't run NUnit 3 tests, so my NUnit 3 test project was being ignored.
To solve the problem:
Uninstall all NUnit Test Adapters (from Visual Studio -> Tools -> Extensions and Updates and from each project's NuGet Package Manager window).
Update all test projects to NUnit 3.0 using each project's NuGet Package Manager Window.
Install the NUnit3 Test Adapter from Visual Studio -> Tools -> Extensions and Updates
Notes:
If you need to stick to NUnit 2, then just install the appropriate Test Adapter. The important thing is consistency.
If you were using test adapters installed by NuGet before, but switched to a Visual Studio Extension, then you may have problems loading resources/files from path strings. See this answer to solve that issue.
Related
I have a solution file which contains two project, one is main project and the other is an unit test project.
I had them install both NuGet Package NUnit and NUNit3TestAdapter
However, I still cannot create nunit unit test near the function I want to test by the mouse right click event
As you can see, only MSTestV2 framework is detected.
My question is: How can I use the NUnit framework to create unit tests in Visual Studio 2022 Community?
The TestGenerator extension has not been released for x64 which VS2022 yet.
What you do is to use command line tools:
Create a new folder for your test projects.
The run :
dotnet new nunit
This will create a new NUnit test project.
Add this project to your solution and add a project reference from there test project to your other project "to be tested", and off you go :-)
I am seeing some very strange behavior for NUnit tests in VS2019, where the same solution works fine in VS2017. There are several NUnit test projects in my soultion.
In VS2017 with the NUnit Runner extension installed, I can see all of my tests in the Test Explorer window and the "run all" button will work and run all tests. Some developers in my organization use Resharper instead of the NUnit extension and this works too.
I have stopped using Resharper because as VS introduces more features, Resharper has made it so slow that VS is unusable.
In VS2019 the Test Explorer window will show all of my unit tests (even without the NUnit extension installed). If I click "run all" it will not run any tests and the Output window will say 0 tests discovered. Coworkers have said that Resharper will run all tests without issue. If I right click a single test project and run just those tests, some projects will run tests, but not all.
For some projects I have tried installing the NUnit3TestAdapater nuget package and this will let VS2019 run that project's test if only that project is selected. This does not work for all projects and it still does not work for "run all".
Does anyone know what might be causing this and what could fix it? I have updated to the latest version of NUnit (3.12) and latest TestAdapter (3.16) for all of these projects.
This has been a real pain for about a year, because I need to keep VS2017 and 2019 both installed, and I need to train new developers on how to work around this weird issue.
I stumbled upon the same problem. It seems to me that I have to install more and more with each release.
In my case (Visual Studio 2019 community edition, version 16.6.1), I now also had to obtain the Microsoft.NET.Test.Sdk via NuGet.
So in the end, I have installed three packages in my test project:
NUnit (3.12.0)
NUnit3TestAdapter (3.17.0)
Microsoft.NET.Test.Sdk (16.7.1)
Turning the automated test discovery on or off did not change anything for me though.
Hope this helps anyone.
The solution turned out to be a combination of two things.
On the top menu, navigating to Test > Options and disabling "Discover tests in real time from C# and Visual Basic .NET source files". This option appears to be incompatible with parameterized tests. The problem is that parameterized tests do not "exist" in source code but are generated by the test adapter at runtime. This also fixed an issue I've seen where the "base" test of the parameterized test shows up in the Test Explorer as a not-run test, even though only the specific test cases are real tests. (In my opinion, this should not be enabled by default because parameterized tests are extremely useful, whereas seeing new tests in the Test Explorer without compiling is a trivial convenience since you must compile to run them anyway.)
Using the NuGet package for the test adapter instead of using the VSIX extension. It seems that for this piece, all that is required is that at least one project in your solution references this. If at least one project references it, all test projects can be run. (This makes sense to me, as it is more compatible with build tools outside of Visual Studio.)
Hooray for breaking changes!
I had the same issue and solved by checking the logging.
In Tools->Options->Test->General setting the Logging Level to Diagnostic. This will produce additional output in the Tests Output Pane of the output window.
In my case the issue was linked to missing version of ".NET Core 3.1 Desktop Runtime"
You can download the last version in https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-desktop-3.1.14-windows-x86-installer
In my case I had to install also the Microsoft.NET.Test.Sdk nuget pack.
After none of the above worked for me.
I just installed xunit.runner.visualstudio nuget and everything is working fine now.
I recently installed XUnit and the XUnit VS runner (i.e. xunit.runner.visualstudio) on Visual Studio following the documentation. The installation process uses NuGet and on completion I can successfully see all tests in the MS Test Explorer.
However, if I start a new solution and reference all the required XUnit dll's, i.e., I want to use XUnit without using NuGet to install it, the tests never show up in MS Test Explorer (no problems seeing them in the ReSharper test explorer).
I think this has something to do with the XUnit test adapter that Visual Studio uses to find XUnit tests. It appears that NuGet somehow instructs Visual Studio to create the VisualStudioTestExplorerExtensions folder on each build putting the necessary XUnit test adapter dll's (e.g.xunit.runner.visualstudio.testadapter.dll) in that folder. The MS Test Explorer then uses this test adapter to find XUnit test (see SO Question).
When I attempt to use XUnit without NuGet, the VisualStudioTestExplorerExtensions folder never gets created on build. Adding the folder manually with all XUnit dll's in it also doesn't work. It's almost as if i need to instruct Visual Studio to look in that folder, but I can't see any obvious way of doing that.
How do I use/install XUnit without using NuGet? Or, how do I get VS to look in the `VisualStudioTestExplorerExtensions' when looking for tests?
If you want to install a test runner manually, copy all the necessary dlls to:
C:\Program Files (x86)\Microsoft Visual Studio {version}\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Extensions
Replacing {version} with the appropriate number.
The drawback here is that this is machine wide (maybe desirable in your case), and that you can't quite as easily replicate this setup on a build server. You also will probably have to restart VS whenever you make changes to these files.
I’m having a "build partially succeeded" issue with this error “NUnit failed to load e:\Builds\184\CSTax\706USServices_Test\bin\Calc.Tests.dll”, but all of the unit test in this project ran and passed (all green).
Build environment
1) Using NUnit 2.6.4 and NUnit Test Adapter 2.0.0
2) TFS 2013 – upgraded from 2012
3) Visual studio 2012 and 2013 have been installed on the server
4) I did install the NUnit Test Adapter, using the Extensions and Updates in 2013 Visual Studio
5) Using build process templates from TFS 2012, even if I switch to the 2013 default build process templates I get the same error
6) I tried changing the project to copy the nunit references locally (including the test adapter), they did make it to the bin folder, but still fails
7) I used process monitor to see if I could find the failure, everything looked good, the dlls were copied from the packages folder to the bin folder and loaded.
I’m sure it has to be something in our build environment, but I do not know where to look, I need my builds to go green. Any ideas?
The issue is a bug in the NUnit 3.0 test adapter, I removed our E2E project off of the build server and all my builds went green. NUnit is looking into this bug.
You need to:
Download the NUnit test adapter: https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d . Rename the NUnitVisualStudioTestAdapter-2.0.0.vsix to NUnitVisualStudioTestAdapter-2.0.0.zip. Unzip NUnitVisualStudioTestAdapter-2.0.0.zip.
Check in the following dlls: nunit.core.dll, nunit.core.interfaces.dll, nunit.util.dll and NUnit.VisualStudio.TestAdapter.dll into a folder in TFS Version Control.
Specify the build controller's path to custom assemblies:
Then queue a build, the NUnit test methods will be run.
Also have a check on the Enable a third-party unit framework part of this MSDN article for the details: https://msdn.microsoft.com/en-us/library/vstudio/ms253138.aspx
I have a specflow scenario, which is a scenario outline with two examples. In Test Explorer window of Visual Studio 2013 I can see it as two separate tests (which is ok), but "Open test" command from context menu doesn't work for them, while it does work for simple specflow scenarios (not "outline" scenarios). Is it somehow possible to quickly open code for such outline scenarios from Test Explorer window in Visual Studio 2013? Or does any other way exist to do that?
P.S. I use SpecFlow integration for Visual Studio 2013
The current version of specflow has some issues mapping code lines for scenario outlines. This pull request has a fix for this and was merged (via this PR) in the vNext branch. I have a version with this fix in it installed and I have just checked and when I choose 'Open Test' or double click on a test in the test explorer I get taken to the scenario line in the test explorer.
In order to use it you'll need to build a version of specflow yourself I thin from the 'v2' branch, at least until a beta version is published on nuget.
In order to use the v2 branch you need to checkout the code and build it. As a result of this you should end up with a nuget package in \SpecFlow\Installer\NuGetPackages\bin\. You will probably want to update the version number in the specflow.nuspec so that you get a proper version number. Once that's done you need to put the nuget package in a folder and then tell visual studio the that folder is a nuget source. Then you can install the nuget package (after uninstalling the old one) and you should be good to go. If it doesn't work then it might be because the extension needs to be updated. Searching the machine for the specflow dlls and replacing them with the newly built versions is probably the best way to go, as the ide integration is a separate package now.
Any other problems let me know, I'll do what I can to help.