Running xUnit tests in TFS Build vNext

As you may know by now, Visual Studio Online and TFS 2015 RC introduced a new build system.  As you start to use the new build system, you may need to run xUnit tests as part of your build.  Out of the box, the new build system includes a Visual Studio Test task.
This task can run MSTest tasks without you having to make any changes.  If you need to run xUnit or nUnit tests, you have to specify the test adapter. 

To get started with this new build system, check out my new Pluralsight course – TFS Build 2015: First Look!

Let me show you how to go from zero to automated xUnit test with Build vNext:

To be able to run xUnit tests from Visual Studio, you have to add and the Visual Studio runner to your solution, via NuGet

Once you add the NuGet packages, you can create xUnit test cases and run them from the test runner. 

To learn more, here is information on creating xUnit test cases:

Once you have your test cases coded, you can commit & push them to Visual Studio Online (or check-in if you are using Team Foundation Version Control).  Now you are ready to create a new build.  From the Build section, create a new build a select the Visual Studio template:

Select your repository:

Then go to the second step on your template (Visual Studio Test):

This is where you need to specify the xUnit test adapter.  If you don’t do so, the Visual Studio Test build step will be looking for MSTest test cases.  The test adapter (xunit.runner.visualstudio.testadapter.dll) will be copied to the bin directory during the build since it is one of the files that are included with the NuGet package.  So under Advanced –> Path to Custom Test Adapter, use this value: $(Build.SourcesDirectory)\XUnitDemo\XUnitDemo\bin\Debug\


And run your build and your test cases will run as part of the build:



If you want to learn more about TFS Build vNext, take a look at my latest Pluralsight course – TFS Build 2015: First Look

About esteban

Esteban is the Founder and Chief Technologist at Nebbia Technology, an ALM consulting and Azure-powered technology company. He is a software developer with a passion for ALM, TFS, Azure, and software development best practices. Esteban is a Microsoft Visual Studio ALM MVP and ALM Ranger, Pluralsight author, and the president of ONETUG (Orlando .NET User Group).

2 thoughts on “TFS 2015 at ONETUG on 10/8

  1. Antwan

    How would we run Specflow (not specrun tests) using the unit test provider MSTest on a TFS build?

  2. bitbonk

    For me this seems to works (all xUnit test are being discovered and run) even without setting “Path to Custom Test Adapter”. Do I need it anyway?

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? *