One of the challenges I was looking to solve recently was running builds in VSTS for .NET Core, and then running 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 is 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
Visual Studio Test and close the dialog.
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
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:
And it should (could) look something like this in total when you're done:
/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:
If you have failed tests, you can simply click the
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 seem to be addressed and working.
From withing VS, you can easily see the build status too:
- VSTest.Console.exe command line options
- This documentation describes the usage of the additional console arguments we're passing in as per my post above.