Running UWP unit tests in VS 2017 - visual-studio

For some reason Visual Studio 2017 does not recognize unit tests in Universal Windows Unit Test App projects.
Steps to reproduce:
Create a new Unit Test App (Universal Windows) in VS 2017
Add Assert.IsTrue(true); to the unit test created
Click on Test -> Run -> All Tests
Expected: unit test discovered and run successfully.
Actual: no tests found.
Output Tests produces absolutely no output.
Comment if there is a log file containing some more info and I'll add it.
EDIT: So it turns out they don't work in 2015 either. I have ReSharper in 2015 which is able to run them. But why can't the VS runner run them?

By sheer dumb luck (or just desperation), I went to my Test project and Deployed it (right click on project-> Deploy). That made the tests appear and now they run.

This now works in Visual Studio 2017 (version 15.4.5 currently).
After building the solution, the tests appear right away. Deploying the test project may have also worked in the older versions.

Related

Why will Visual Studio 2019 will not run my unit tests?

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.

How to connect OpenCover to VS tests

OpenCover 4.7.922 installed in VS 2015 Community, and appears in VS menu bar, but the link to my Tests is broken. Project is a C# console app.
This was working a while ago, with the same project. Possibly disturbed by (1) installing VS 2019 (Now Community 2015 and 2019 are both installed) and (2) updating OpenCover.
OpenCover Text Explorer should find my tests, enabling me to run them. But no tests are found. Likewise, under Test Explorer, "Run selected tests with OpenCover" is disabled (greyed out).
It's working now. Final stage was to delete the test project entirely and rebuild it, and make sure all projects use the same Target framework.
In summary, I am getting my code automatically colored (covered / not covered) using VS Community 2015, Target Framework 4.5.2, OpenCover 4.7.922, NUnit 3.12.0.

VisualStudio 2017 preview 2 doesn't load Unit tests with .NET Core 2.0.0-preview2-006391

In the last two days I've had some trouble with Unit Testing in VS 2017 preview 2. Yesterday I've installed the last version of .NET core, I've updated every package inside my project and, since then, I haven't been able to see not a single test in VisualStudio's Test Explorer . If run the command "dotnet test" in the PowerShell everything works and I receive the information of test's execution. What can I do? Thanks!
Ok, I've opened an issue on the official VisualStudio github, 'cause it seems that this version of Vs is quite instable.
https://github.com/microsoft/vstest/issues/858
;)

Visual Studio 2012 Professional - unit tests not working

After building my application I get in the test output:
------ Discover test started ------
Exception has been thrown by the target of an invocation.
========== Discover test finished: 1 found (0:00:01,457) ==========
I'm using Visual Studio 2012 Professional on win7 32bit.
Tried:
repairing vs2012
reinstalling vs2012
changing configurations
changing path to
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Nothing worked...
Any ideas?
Previously I worked with Visual Studio 2010 Express edition.
Application is correct - I made just simple class library and test project just to be sure it works. And it doesn't. The same project works with my student premium version.
Ok
I looked again in http://connect.microsoft.com/visualstudio and tried also:
moving project files to another location than default
changing security rights in files and folders properties
run vs as administrator
Nothing really worked until i found by chance vs2012 update 1
(under the "Additional Software" category)
After download and installation everything works fine.
In my case, right clicking and selecting "Debug Tests" on a test method would not do anything. It was an existing test project. The issue was that the test project was not even included in the solution's build list. Somebody took it out from the solutions build list. Anytime I would select "Debug Tests", the projects were built but nothing happened.
Confirm that the test project is going to be built with the solution by right clicking on solution in the solution explorer, and then configuration manager. Ensure that the test project is checked-on for build. Those minor things that cause big problems!

Unit Tests are failing on a "Build failed" in the Session window with no message providing a reason for failure in Visual Studios 2010

I had recently installed VS 2010 on my local machine, and cannot seem to get Resharper 5.1 and the unit tests to work correctly.
Whenever I try and run Unit tests I get a "Build failed" with the test icon remaining gray, but with no info in the output window and no discernible reason why.
The Unit Tests run perfectly fine when doing a nant build.
Running a previous branch of the code on VS 2008 does not have this same issue as a result.
Any ideas?
Check your build configuration. If you're using a build configuration that is set to not build your test projects (like your release configuration) then the Resharper test runner will fail this way. The output looks like a perfectly successful build but if you inspect the output you'll find your tests are not in it.
Another symptom of this issue is if you set the test runner to not build as suggested above, next time you attempt to run the test it will be crossed out in the test runner.
Build configurations can be found in Build->Configuration Manager in Visual Studio.
If you change the build settings to 'never build' in the unit test sessions window, it works ok (providing you pre-build the dll using visual studio). It appears to be a Resharper bug.
In my case this did solve the issue:
http://www.shirmanov.com/2011/07/project-has-not-been-built-resharper.html
I had the UnitTests set "to not build" in my solution configuration.
The above mentioned article shows this very detailed.
In my case I was missing a DLL that was not added to the project. I added it, cleaned and build and everything was okay.
Verify in Visual Studio Configuration Manager that your test projects are marked to be build.

Resources