Looking for something?

Running Unit Tests for your .NET Core projects in Visual Studio Team Services (VSTS)

One of the challenges I was looking to solve recently was running builds in VSTS for .NET Core, and then run any C# unit tests I had in dotnet core. This is pretty straight forward once you've figured out how - so this post is a short one, aiming to help anyone looking for build and test automation in VSTS with DotNet Core.

A small tip-of-the-day post for you. Enjoy.

Configure Test Task

In Visual Studio Team Services (VSTS) the easiest way to run any unit tests are with the build-in task in VSTS for running tests. When you're editing your build definition, hit the Add build step... button and select Test -> Visual Studio Test and close the dialog.

MS Test Build Step in VSTS

If you've used VSTS/TFS before you are probably somewhat familiar with this. The crux comes with configuring the parameters.

Add Test Build Step

With .NET Core we are actually not going to point the test build step to your Assembly, which you could imagine would be the case given that it's how we've done it in the past. With .NET Core projects, you should instead point this task to your project.json file. Configure the details of the build step and ensure that the Test Assembly step points to one or more of your project.json files.

Configure "Advanved Execution Options"

We've pointed our test task to use the project.json files instead of the assemblies. But we still have one more thing to configure; The Other console options.

In this box, you enter the following:

/UseVsixExtensions:true /logger:trx

And it should (could) look something like this in total when you're done:

Full Test Ste Configuration for the VSTS Test Build Step for .net core

/UseVsixExtensions:true is a way to tell the vstest.console.exe process to use the VSIX extensions that are installed (which enables us to run these tests).

/Logger:trx simply states that we want our results to be logged into a Visual Studio Test Results File (TRX). This is what makes the results look so nice and shiny in VSTS, as they're parsed like any other test results. Winning.

Verify build and tests in VSTS

Done, that's it. Very simple, once you've figured those details out for the configuration - and as you can see here, the test results are fully integrated in Visual Studio Team Services (VSTS) just like if it were a normal Unit Test project based on the full .NET framework.

Test results in a .NET core project:
Successful build including the overview of the tests

If you have failed tests, you can simply click the Tests link.

Verify build and tests in Visual Studio

I'm spending a lot of time in Visual Studio, and one of the things I really enjoy working with is the enhanced integration with the VSTS builds. A while back this wasn't as thoroughly thought through and didn't work as I expected it to. Currently, most things related to VSTS/VS integration seems to be addressed and work.

From withing VS, you can easily see the build status too:

Use Visual Studio to verify Build Status

References

0 Comments 01 November 2016
Tobias Zimmergren

Tobias Zimmergren

Hi, I'm Tobias. I am a Microsoft MVP for SharePoint and I use this site to share my thoughts on tech with you on topics like SharePoint, Office 365, Azure and general web development.

  Malmö, Sweden

Related Post

Comments powered by Disqus
res.