What is the easiest way to get TFS 2013 to run unit tests via VS 2015 - unit-testing

We have Team Foundation Server 2013 installed with Visual Studio Professional 2015 and I've been able to get continuous integration builds working using the TfvcTemplate.12.xaml build process template and the "/tv:14.0" MSBuild argument. However, I can't seem to find a way to tell TFS to use the 2015 Unit Test suite.
This post Build VS 2015 Solution w/ Unit Tests on TFS 2013 Team Build worked around the problem by installing VS 2013 on the build server, but that means that the build server would use the 2013 testing framework rather than the version used by the developer.
Another option is to use an older build process template that uses MSTest, which supports the "ToolPath" parameter, but MSTest appears to be deprecated (MSTest V2). BTW, I tried using the MSTest V2 NuGet packages, but that didn't have any effect on the framework used by TFS, which made sense once I thought about it.
I assume that there should be some way to tie in a third-party testing framework, but the examples I've found use the older build process template.
Has anyone else found a solution for this?

If you need your test agent or test controller to work with TFS 2013,
use Agents for Microsoft Visual Studio 2013 Update 5 and
configure the test controller.
Source Link: Install and configure test agents
This is the official recommended practices, we don't suggest you to use some third-party testing framework for handling your situation (not sure if there were).
Besides just as MrHinsh commented, we encourage you to move to new web-based build system which is more excellent. For the detail benefit of VNext builds, you could refer to this article Why You Should Switch to Build VNext

Related

Unit test .Net Framework 3.5 project in VS 2017

I have some legacy projects with test libraries.
The projects (and unit tests) target .NET 3.5.
We are using VS 2017 enterprise.
I was able to locate some nuGet packages that would allow the tests to build correctly, but Test Explorer does not see the tests at all. I presume this is because there is no Test Adapter.
The packages I am using are:
Microsoft.UnitTestFramework.Extensions v1.0.0.3
Microsoft.VisualStudio.QualityTools.UnitTestFramework.Updated v15.0.26228
Most of the packages I found would not install due to a lack of .Net 3.5 support. Which makes some sense in 2017, but still.
Does anyone know what Test Adapter I can use to make legacy .Net 3.5 unit tests visible to VS 2017 Test Explorer?
Things I can't do:
use a different version of VS
re-target the libraries to a different framework version (they are for SharePoint 2010)
Rewrite all the tests for a different test framework (unless there's a very straight forward translation of the attributes/asserts I could do with find and replace, as there's a lot of tests)
Appreciate any tips!

How do i specify Visual Studio test runner in tfs build script

I have used Microsoft shims in my project for writing unit tests. These tests run fine on my local machine, however when build on server the tests fail as the ms test runner does not support shims. After searching alot i found that i have to specify vs test runner to run test but it can be specified only in default template. Is there any way to specify the test runner in build script file.
I am using TFS 2013 on TFS server with upgrade template.
The Upgrade template was provided only for backward compatibility for folks that has serious customization investment in 2005/2008 builds. I would not expect new functionality to work in legacy builds without serious rework and effort.
I would suggest that there will likely be less effort in moving your build to the modern build templates and gain access to new features effortlessly.

Cucumber js in visual studio 2013

Is there a project with similar goals as Specflow is to cucumber in Visual Studio, but for cucumberjs?
I'm considering a unit testing / bdd framework for Visual Studio. Cucumberjs seems like the obvious choice as I am using Specflow to test the c#. However cucumberjs requires nodejs to be installed.
Chutzpah runs things like jasmine, qunit etc in Visual Studio. Is there a way to do the same for cucumberjs? Perhaps nodejstools for visualstudio with a mixture of something else?
There is a Feature request: Cucumber-js support for Chutzpah, but it's work in progress.
(Chutzpah was moved to github, so the issue was lost)
A new Chutzpah feature request on github for cucumber-js support
There is an interview with a cucumber core member saying (below) which sounds promising:
"Support for Cucumber.js is being added to popular IDEs like Jetbrains
Webstorm 8 and Visual Studio."
As per David Leitner's reply, I've created a step-by-step guide to setting up cucumberjs in Visual Studio.
http://blogs.endjin.com/2015/10/step-by-step-guide-to-setting-up-cucumberjs-in-visual-studio-2015/
I've done this by using the Visual Studio Task Runner Explorer. (You have to add it if you use VS 2013, with 2015 it's already included.)
This Extension is a task runner for Grunt and Gulp directly within Visual Studio 2013. It is now possible to define a Grunt task, like this one which runs your cucumberjs Features.

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.

VSTS Unit test - build system

I have developed a build system on MSBuild (NET 3.0) and cc.net to perform continuous integration builds of a Visual Studio 2008 application, however a developer on the team recently added a VSTS unit test project to the mix. Is there any SDK or add-in provided by microsoft to allow this to be compiled on a non-team system build environment?
You can run the tests from the command-line, but it requires that the Test Edition of Visual Studio be installed on your build server:
http://devlicio.us/blogs/derik_whittaker/archive/2008/09/25/clean-build-server-with-mstest-fail.aspx
http://aspadvice.com/blogs/ssmith/archive/2008/03/18/Continuous-Integration-Setup-with-MSTest.aspx
This person is doing MSTest with CC.NET, so it might be helpful:
http://testearly.findtechblogs.com/default.asp?item=630602
In general, this is a main reason why many people choose something like NUnit, xUnit.NET or MbUnit over MSTest.
If you use MSTEST You will have to put that edition on the build server. To cut a long story short youd be better off changing the testing framework the developer is using from MStest to Nunit.
Its a much lighter solution.