How to connect OpenCover to VS tests - visual-studio

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.

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.

Running UWP unit tests in VS 2017

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.

Visual Studio 2015 (and 2013) Build and Clean Fails with no errors but MSBuild (v14) succeeds

My ASP.net Web Application solution will not build nor clean in Visual Studio 2015 and VS2013.
It was originally written in VS 2010. The same sln (consisting of 3 projects) builds just fine in VS 2010 and VS 2012 but I get build failure on all 3 when building the solution or the individual projects as well as cleaning them.
There are NO errors and nothing is shown in the output window even with verbosity set to diagnostic.
There have on occasion been some warnings with regard to files not up-to-date but those are shortlived and not completely reproducible.
I'm able to successfully build via msbuild in the VS14 command line so this has got to be something IDE related.
Any suggestions out there?
I've seen numerous posts on this type of problem and none of the suggested workarounds/fixes work for my problem.
Also, what I'm experiencing is not exactly the same as I've seen posted.
I've just upgraded to the latest "update 1" available from MSDN and that didn't help.
tia
ryan

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!

Visual Studio 2010 Test View doesn't find 2nd NUnit test project

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.

Resources