Following my previous post, I’m building Asp.Net Core web application and I’m running my tests in XUnit. Default VSTS template for Asp.Net Core application runs the tests but it does not publish any results of test execution, so going into Tests results panel can be sad:

And even if you have a task that publishes test results after dotnet test, you will not get far.

As it turns out command dotnet test does not publish any xml files with tests execution results. That was a puzzle for me.

Luckily there were good instructions on XUnit page that explained how to do XUnit with Dotnet Core properly. In *test.csproj file you need to add basically the following stuff:

<Project Sdk="Microsoft.NET.Sdk">


    <PackageReference Include="xunit" Version="2.3.0-beta2-build3683" />
    <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta2-build3683" />


Make sure you don’t miss the DotNetCliToolReference line – this is the key here.

Run dotnet restore and dotnet xunit inside the folder with this project. If you try to run this command outside of this folder you’ll get an error.

Command dotnet xunit has an option to output test results as XML file: dotnet xunit -xml .\test-results.xml.

Because this needs to be executed inside of the tests folder we can’t use “.Net Core” build task from VSTS – there is no option to configure what is the base execution folder. Instead you can just add “Command Line” task to execute what we need and from the correct folder:

Add “Command Line” task. As Tool option give it dotnet, for arguments say xunit -xml ./test-results.xml and make sure you specify the working folder – for my case that was src/Tests.

After that add “Publish Test Results”, tell it to use XUnit format, the rest of the default parameters worked for me.

And BOOM! We have tests results published at the end of the build:

  • Mike Clark

    You could still use dotnet test with xunit if you use the TRX logger

    dotnet test -l trx;test-results.xml

    • yeah, I’ve seen Donvoan Brown talking about this as well:

      Only I’ve seen it after I wrote this

      • Tarig0

        This is better it can publish partial tests if you allow for the exit code 1 to not fail the build step

    • SchmidtTroy

      Wanted to share the inline PowerShell script I have running. I had to do this because I have a .sqlproj file in the solution folder so dotnet by default wants to grab any .*proj file and then ends up throwing an error in the CI build. I already have the restore and build steps before testing so I included those switches to turn them off.

      # Write your powershell commands here.

      foreach ($test in ls tests/*.Tests) {
      Push-Location $test

      echo “build: Testing project in $test”
      $project = $test|split-path -leaf
      & dotnet test –logger “trx;LogFileName=TestResults.$project.xml” –no-build –no-restore
      if($LASTEXITCODE -ne 0) { exit 3 }