Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get .NET Core 2.0 xUnit test reports into VSTS

How do I get .NET Core 2.0 xUnit test reports produced and published into VSTS?

like image 892
Luke Puplett Avatar asked Dec 18 '22 03:12

Luke Puplett


1 Answers

Follow the getting started as per this document:

https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test

Importantly, this must be in your test project file:

<ItemGroup>
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
  <PackageReference Include="xunit" Version="2.2.0" />
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

Now in your VSTS build configuration you need to pretend like it's all VSTest and not choose or try to use the xUnit runner and reporting formats.

So, add a .NET Core task as v2.0 (preview) and set, in additional to other obvious settings:

Command: test
Arguments: --logger:trx --configuration $(BuildConfiguration)

Now add a good old fashioned Publish Test Results task and set:

Test result format: VSTest
Test results files: **\*.trx
Merge test results: check
Upload test results files: check

I think now the Visual Studio runner will run as xUnit, but produce its own reporting format that VSTS copes with.

Note The only bug I saw was that the 'Run duration' was crazy long in the report.

like image 119
Luke Puplett Avatar answered Dec 28 '22 10:12

Luke Puplett