'Capturing test output with XUnit.Net and VS2017

VS2017 Community Edition comes with test project templates for Xunit pre-installed. I have a Dotnet Standard 1.4 class library and a Dotnet Core 1.1 XUnit test project. This works well, everything builds, I can run all tests from the Visual Studio Test Explorer, and if my tests write to an ITestOutputHelper the Test Explorer shows an 'Output' link where I can view the output of the tests.

The problem is that if I have a load of tests I don't want to have to click on every test, and then on every 'Output' link in order to view the results. instead I want to see the results in some sort of output file.

The Xunit documentation indicates that it does have the ability to output test results in xml.

http://xunit.github.io/docs/format-xml-v2.html

But it doesn't explain how to get it to do it.

How can I get Xunit to save test output to a file?



Solution 1:[1]

xUnit logger can generate xml reports in the xUnit v2 format (https://xunit.github.io/docs/format-xml-v2.html).

  1. Add a reference to the xUnit Logger nuget package in test project.

  2. Use the following command line in tests:

    dotnet test --test-adapter-path:. --logger:xunit
    
  3. Test results are generated in the TestResults directory relative to the test.csproj. A path for the report file can be specified as follows:

    dotnet test --test-adapter-path:. --logger:xunit;LogFilePath=loggerFile.xml 
    

    loggerFile.xml will be generated in the same directory as test.csproj.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shA.t