Blog

Execute and publish xUnit Tests results with .NET Core and VSTS

31 Jul, 2016
Xebia Background Header Wave

At the moment of writing you can not use the standard Visual studio tests task to run your xUnit unit tests on DotNetCore 1.0 and then publish the results to VSTS.

You need some different steps to get DotnetCore compiled and run your unit tests in a VSTS build. Here are the steps to make it work:

Pick the standard Visual studio template for your build:

image

In this default build workflow first add a command line to run a dotnet restore command so your build of your solution will succeed. do this right after the nuget restore step:

image

In the command line options set the tool to : dotnet and the command line argument to: restore

image

Now our solution should build.  The next step is to replace the Test assemblies task since in dotnet core you run your unit tests also using the dotnet command line. So we replace this task with a new command line task and provide it the following arguments:

test $(Build.Repository.LocalPath)<locationoftestproject> –no-build -xml testresults.xml

Of course here you replace <locationoftestproject> with the correct location of the project containing your unit tests. In my case I was using the MVC music store sample project (which can be found here: GitHub – aspnet/MusicStore )and for this I needed to replace the test location to: testMusicStore.Test

Note that the additional arguments instruct the framework not to build the solution again, since we already have done this and would be a waste of time. The –xml option provides the name of the xml test results file that we want as output so we can publish the results to VSTS.

image

Now we have run the tests, so the final step is to publish the results to VSTS. For this we use the Publish test results task

image

And for this task we need to provide the name of the file it needs to publish. this is of course the name of the file we specified as the –xml output. We also need to specify that the results file contains test results in the xUnit format. Default it is set to use the JUnit format. But this is a simple select from the dropdown test Result Format.

So the final settings for the Publish task should look like this:

image

Now we can run our build and you will see the following results appear:

image

As you can see our tests are run and nicely reported. In this screenshot I switched to the tests tab in the results views that are available for a build and changed the outcome to show all results. Here you can see all de details of every test you have, when they have started failing, and how long they run.

As you can see all integrates nicely, only not with our default Visual Studio test task. I assume we might see this integrated in the future when we get new releases of the build tools for DotNet Core, but for now this is a pretty nice and clean solution to get things up and running.

Enjoy!

Marcel

Marcel de Vries
Marcel is a key figure in the technology sector, serving as the co-founder and Global MD & CTO of Xebia Microsoft Services. He is deeply involved in advancing organizational capabilities to deploy software swiftly and securely, emphasizing the importance of innovation and productivity while maintaining compliance. Marcel is passionate about technology and continuous learning, often sharing his insights at leading industry events and through online courses on Pluralsight. Recognized for his contributions, Marcel has been honored with the Microsoft MVP award for over 17 consecutive years and is a Microsoft Regional Director since 2008. His expertise spans across Cloud Adoption Strategies, DevOps, and various cloud computing frameworks, making him a respected voice in the tech community.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts