Visual Studio 2012 Express Web ignores Unit Tests - unit-testing

a quickie, that you might already have solved :
I have a Test Project created in VS2010 SP1. The Project is imported into VS2012 Express. The Test Explorer Window shows no Tests (although there are two for now). So I click "run all", which results in the following Console Output (roughly translated, don't know the exact unlocalized equivalent) :
========== Build: 0 successful, 0 erroneous, 2 current, 0 skipped ==========
No Results, no Tests in Test Explorer...Any ideas?
TIA!

Obviously, the problem was based on the fact that the test class library was created in VS 2010. On the following screenshot,you can see the project that gets ignored by the VS 2012 test runner (bottom icon) and a newly created c# .Net 4.0 Test Project with all tests being executed as intended (topmost icon).

Related

Visual Studio Enterprise 2019, "Profile" unit test causes error: file contains no data buffers

After right-clicking a unit test in Test Explorer in Visual studio 2019, and selecting "Profile", the following happens:
All associated projects all built and instrumented, as evidenced by output by Test logging to the Output window, like ** Instrumented C:\Users\Me\Source\Repos\MyRepo\<ProjectPath>\Project.UnitTests\bin\x64\Debug\net472\MyProject.dll **
The unit test runs and passes
A new tab with a name of "[UnitTestName][Date][Time].VSP" appears with "Preparing to open report..." in the middle
An error occurs, "File contains no data buffers"
I've made sure all the projects have this in their csproj file:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
Also made sure symbol servers are set up. Any ideas what else to try to get profiling of unit tests working in VS2019?
Through trial and error, discovered there are two things that need to be set to get the Profile option to work (using Visual Studio 2019 and NUnit 3 adapter):
You need the project under test and any of its dependencies switched
to target "Any CPU", under Project > Properties > Build tab >
General section > Platform Target dropdown.
From the Visual Studio bar, Test > Processor Architecture for AnyCPU Projects - change it to x64.
Profiling should then work. If you don't do the second step, you'll get Test output errors like:
Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
and/or
No test matches the given testcase filter 'MyTestName'

How to disable test discovery in visual studio 2017?

I have some solutions with a bunch of projects and we have no unit test project in these solutions. However Visual Studio 2017 is still trying to discover unit tests and slowing down our process.
https://imgur.com/a/89Vt1P6
I looked at the runsettings xml file but there was nothing in there to disable it
https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file
any idea how we turn this unnecessary stuff off for some of our solutions?
Thanks
This was driving me crazy too. One day it just started running test discovery after every build, and switching my output pane to "Test" which is annoying.
How I fixed it in VS 2015 (may be the same for 2017),
disable (uncheck) this setting:
Test menu --> Test Settings --> Keep Test Execution Engine Running

Can't run unit test Visual Studio 2012 Ultimate

When I try to run a specific test on Visual Studio 2012 Ultimate, I have an error message : "Process with an Id of -1 is not running" (not sure of the translation, sorry).
And when I try to execute all the tests, the error message is "The specified file can't be found".
All my tests are detected, but none are executed. I've spent two days trying to make these tests work: recreating the test project, running the tested project under IISExpress instead of IIS, renaming the IISExpress folder in My Documents, forcing the compilation for x86 or x64, removing fakes assemblies, cleaning solution... nothing worked.
I use the built-in MSTest framework, and no specific framework is installed.
Here is the message I get in debug:
And here is what I get when I "only" execute:
English error messages:
------ Run test started ------
Process with an Id of -1 is not running.
========== Run test finished: 0 run (0:00:00,1050004) ==========
------ Run test started ------
The system cannot find the file specified
========== Run test finished: 0 run (0:05:16,7847051) ==========
After debugging Visual Studio itself it turns out that Visual Studio is trying to launch vstest.executionengine.x86.exe.
Which doesn't exist in your instance of 2012:
Solution
I repaired Visual Studio 2012 from the Programs and Features panel of Windows and that fixed the tests.
Upgrading it to Visual Studio 2012.4 seems to keep the tests in a running state. If you choose to repair 2012, make sure you also re-apply the latest update pack (Update 4), if you had an update installed.
Opening the project in Visual Studio 2013.4 or 2015 Preview also seems to work. So it seems that something has broken Visual Studio 2012 Ultimate somehow and repairing it resolves the issue.

Getting F# tests to be detected by Visual Studio 2013 Express for Desktop

I've defined the following F# file:
module MyFsTest
open NUnit.Framework
open FsUnit
[<Test>]
let ``1 + 1 = 2``() = Assert.AreEqual(2, 1+1)
yet when I try to run them either through "Test Explorer" or "Right Click + Run Tests" a build is done yet no tests are detected/run:
------ Discover test started ------
========== Discover test finished: 0 found (0:00:00,0320018) ==========
After googling a bit I've found my approach seems to resemble the steps taken # http://davesquared.net/2013/03/hello-world-testing-in-fsharp.html, so I was wondering if there's something else I might be missing?
To use NUnit tests with the built-in Visual Studio test runner, you'd need to install the NUnit test adapter. This is available for Visual Studio 2013, but I believe it is not possible to install it as an extension to the Express edition.
However, the Express edition includes support for the Microsoft Visual Studio testing framework, which is supported by the built-in test runner. The usage should be pretty similar to NUnit - you'll just need different namespaces.

Why is the xUnit Runner not finding my tests

I have a xUnit.net Test as follows:
static class MyTestClass
{
[Fact]
static void MyTestMethod()
{
}
}
The xUnit plugin for VS 2012 says:
No tests found to run.
TestDriven.net runs it fine but mentions something about Ad hoc:
1 passed, 0 failed, 0 skipped (see 'Task List'), took 0.47 seconds (Ad hoc)
TeamCity, xunit.gui.exe and xunit.console.exe and Visual Studio also can't find TestMethod
(I've got xunit.runner.visualstudio installed and VS is seeing some tests.)
What gives?
TL;DR your Test Classes must be public (but your Test Methods can be private and/or static)
For reasons of efficiency, the xUnit authors have opted to not use BindingFlags.NonPublic when searching for Test Classes in the runner (the MSIL metadata tables don't index private(/internal) classes to the same degree hence there is a significant performance difference in the relative efficiency that Reflection can thus achieve).
As a result of the above, the fact that your class is private means it doesn't get picked up.
The fact that the Test Method is private and static is fine - xUnit by design since 1.0 has supported both those aspects.
Note that the Visual Studio xUnit Runner extension, xunit.console.exe (and the GUI), the xunit MSBuild task, Resharper and CodeRush are all consistent in honouring this (although arguably they [especially the latter two] could do more to flag when a Test Class (i.e. class [potentially indirectly] containing Fact-derived annoations) is private).
The reason TestDriven.net runs your test is that the Author of TestDriven.net has put great effort into making it Just Work. It internally uses a special Test Runner wrapper/shim (termed the Adhoc Runner) to run your test. Be aware that the method is actually not being run via the xUnit.net runner and hence any attributes you put on your test that have side effects will not be triggered.
Notably NUnit (and I'm pretty sure MSTest) do use private reflection [and hence pick up tests in private classes] which is probably why it never seemed an important thing for you to worry about before.
Note: A side effect / trick enabled by this is that you can make a Test Class private as a quick way of Skipping all tests in a Test Class [and any nested classes]. (Sadly the cases on this planet of this being used unintentionally vastly outnumber the intentional cases of this though!)
This answer is for VS 2013, but the steps are essentially the same for VS 2012. This applies for running via ReSharper's unit test functionality.
Install the xUnit.net runner for Visual Studio 2013 (be careful running Visual Studio as an Administrator, or the tests may not run when running the IDE as a non-Admin):
a. From within Visual Studio 2013, go to Tools -> Extensions and Updates -> Online
b. Search for xUnit.net runner for Visual Studio 2012 and 2013
c. Then download (install) it. If upgrading to VS 2013 from VS 2012, it is suggested that this be uninstalled, and then re-installed.
d. Restart Visual Studio.
If ReSharper is installed, install the xUnit.net test runner plugin :
(NOTE: Since ReSharper 2016.1, xunit support is built in to ReSharper, meaning the xunit plugin is no longer required.)
a. In Visual Studio 2013, Navigate: Resharper -> Extension Manager.
b. On the left, select Online.
c. Search for “xunit.net”. Select the “xUnit.net Test Support”. Click Install.
d. Restart Visual Studio 2013.
“Clean” the solution
a. In the IDE, in Solution Explorer, right-click the solution, and choose “Clean”.
b. Re-compile.
c. Now, when right-clicking a [Fact] attribute, select Resharper’s “Run Unit Tests” (as opposed to the default “Run Tests”)
Troubleshooting running with XUnit:
If problems running the [Fact] tests with XUnit persist, it might
be necessary to manually remove the xUnit package from any/all of the
following folders (review content for the xunit DLLs, then delete
xUnit folder if found):
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\
C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\
As for ReSharper, try un-installing and re-installing the
xunitcontrib library (xUnit.net Test Support). I have noticed once
when un-installing, some error messages flashing past. I grabbed a
screen-shot at one point, and it listed:
Access to the path
C:\Users\<username>\AppData\Local\JetBrains\ReSharper\vAny\packages\xunitcontrib.1.3.0\ReSharper\v8.1\plugins\xunit.dll
is denied.
... and the same for the other DLLs in that directory
To resolve this, delete the C:\Users\<username>\AppData\Local\JetBrains\ReSharper\vAny\packages\xunitcontrib.1.3.0\ directory after uninstalling from Visual Studio, then run Visual Studio as a non-administrator, and re-install via ReSharper (Resharper -> Extension Manager)
From http://xunit.github.io/docs/getting-started-desktop.html#run-tests-visualstudio:
If you're having problems discovering or running tests, you may be a
victim of a corrupted runner cache inside Visual Studio. To clear this
cache, shut down all instances of Visual Studio, then delete the
folder %TEMP%\VisualStudioTestExplorerExtensions. Also make sure your
project is only linked against a single version of the Visual Studio
runner NuGet package (xunit.runner.visualstudio).
I had the same issue in VS2017 RC, .NET core 1.1 project. Updating xunit.runner worked for me,
Install-Package xunit.runner.visualstudio
(As referred to by #Kyle in the comments on the other answer) The same No tests found to run message can result from using NuGet to get xUnit.dll and ending up with version 2.0.0 (which is currently marked as prerelease as some core functionality like discovering of v1 tests etc. has yet to be implemented in that branch).
The resolution in this case is to select Stable Only versions (as opposed to Include Prerelease) in the NuGet package manager.
I've been having this issue with .NET Core for a while now where a test class or a test method is not being discovered. The following fix works for me:
Open a command prompt window.
Change to the project directory.
Build the project running the following command:
dotnet build
NOTE: Building from Visual Studio.NET will not work! <<<<<<<<<<< IMPORTANT!
Run the tests: Test --> Run --> Test All - CTRL+R +A (this will discover the new test(s) - but not run the the new test(s).
Run the tests again.
In my case, in order to see any tests, I had to complete the following steps:
(All installed through NuGet Package Manager)
Install xUnit v2.0.50727
Install xUnit.extensions v2.0.50727
Navigate to the following link and follow the steps outlined in the documentation: http://xunit.github.io/docs/running-tests-in-vs.html
I'm using Visual Studio 2013 Premium. (Resharper NOT installed)
For me, the combination of my test class and test method names were too long; xUnit appears to have some cap on this combination.
Shortening the name of just the test method allowed xUnit to discover that single test. Shortening the name of the entire class allowed xUnit to discover all tests in the class.
Threshold of class name + method name appears to be 172 characters.
My problem was that I updated xunit.runner.visualstudio to version 2.4.5. However, the project I am working for, is for .NET Standard 2.0. Therefore, I had to downgrade to version 2.4.3 of xunit.runner.visualstudio, since it supports ".NET 2.0 or later". But since version 2.4.4, ".NET Core 3.1 or later" is supported.