microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.49k stars 2.61k forks source link

Execute and publish xUnit Tests results with .NET Core #2126

Closed rschiefer closed 8 years ago

rschiefer commented 8 years ago

I'm struggling to get my xUnit tests from a .NET Core app executing and the results published to my VSTS build. What's the trick?

I've tried the VS Test task with the xUnit test adapter package restored at the solution level. The tests aren't found.

I've tried running "dotnet test" and publishing test results but they aren't found.

I likely missed some setup on one of these but need help at this point.

ccit-spence commented 7 years ago

@brunobertechini I was able to get the unit test to show using the directions from this blog.

http://donovanbrown.com/post/Where-are-My-Test-Results

It was surprisingly simple.

Coder3333 commented 6 years ago

@Sebosek 's answer got me most of the way there, but I think the -xml flag has been removed.

  1. Add the XunitXml.TestLogger nuget package to my test project
  2. Use a dotnet test task and add the Argument -l:xunit. The -l:xunit tells it to log using XunitXml.TestLogger
  3. Add a Publish Test Results step for XUnit with the results file path of "**\TestResults\TestResults.xml", which is where the logger will put the results.
Tarig0 commented 6 years ago

Does anyone know if we can have dotnet test publish failed tests as well? When I try the Donavan link it just fails the build

georgekargakis commented 6 years ago

You have to keep in mind when you use dotnet test

 - task: DotNetCoreCLI@2
    displayName: Run Unit Tests
    inputs:
      command: test
      publishTestResults: true

This option appends --logger trx --results-directory $(Agent.TempDirectory) to the command line arguments.