How to use Nunit custom result writer in Azure DevOps

85 Views Asked by At

I use Azure Test Plans to run my integration tests. I want to apply Unit '--result:path/to/result/file.result.xml;format=custom' to get short result instead of '.trx' that contain a lot of redundant information. I've tried to use Releases -> Task -> Test run for Test plans and set this parameter to unit adapter through console but get an error. May be you know the way how to apply this param to get short test result.

I expected that when test run finished in Run Attach I will get *.xml file instead of .trx file. I have custom extension method for Nunit that describes *.xml result file.

Best regards, Vladimir L.

2

There are 2 best solutions below

1
Andy Li-MSFT On

To generate a test result with XML format for NUnit tests in Azure DevOps, you can use the NUnitXml.TestLogger package.

Add the NUnitXml.TestLogger package to your test project. In your test project, add the following code to the .csproj file:

<ItemGroup>
  <PackageReference Include="NUnitXml.TestLogger" Version="3.1.15" />
</ItemGroup>

In your build pipeline, add the following command to the dotnet test task:

dotnet test --logger "nunit;LogFileName=TestResults.xml" -- NUnit.ShowInternalProperties=true

Tried that in VSTest task by specifying /logger:trx;LogFileName=Nunit-test-results.xml in the "Other console options". From the logs we can see that the xml format test result file is generated, but the VSTest task tries to find the trx format test results to publish which is not existing there and failed test task.

So, maybe you can try the dotnet test in pipeline.

0
Michał Cichoń On

You can create .runsettings file and this file should include as follows:

<NUnit>
        <TestOutputXml>{PathWhereXmlFileWillBeSaved}</TestOutputXml>
</NUnit>

This will generate Test result xml file for your test run(will include all test results). After that you are able to create artifact which include this file or other actions on this file.