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.
image
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 xUnit.net and the Visual Studio runner to your solution, via NuGet
image

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

To learn more, here is information on creating xUnit test cases: http://xunit.github.io/docs/running-tests-in-vs.html

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:
image

Select your repository:
image

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

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\

image

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

image

image

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

5 thoughts on “Running xUnit tests in TFS Build vNext

  1. Raj Kosaraju

    Thanks for the details on how to create charts. I created a few charts with a few test suite in each project. When I created a chart, it shows a few test suites and shows “Other”, which will combine all other test suites. How do I make it show all test suites by name?


Leave a Reply

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