I have a test project written in dotnet core. This need to publish the results in an XML or HTML format. Is there a way I can publish the results to a particular directory using the same command?
--result-directory
is not working for me
How to publish results using dotnet test command
77.5k Views Asked by Raghavendra Bankapur AtThere are 4 best solutions below

I had success today with the nuget package JunitXml.TestLogger, version 3.0.114: https://www.nuget.org/packages/JunitXml.TestLogger/
To add as a dependency:
dotnet add package JunitXml.TestLogger --version 3.0.114
Once added as a dependency it was simply a matter of executing:
dotnet test --logger:"junit;LogFilePath=dotnet-test-result.xml"
At today's date JunitXml.TestLogger has four times as many stars as the nuget package JUnitTestLogger mentioned in another answer. JunitXml.TestLogger is being actively maintained, whereas JUnitTestLogger has not been touched for 2 years.

After stumbling on the same problem (I wanted to publish test results in JUnit format), I ended up finding the JUnitTestLogger NuGet package.
It was a matter of installing it:
dotnet add package JUnitTestLogger --version 1.1.0
And then running the tests as:
dotnet test --logger "junit;LogFilePath=path/to/your/test/results.xml"
Edit: Check the more recent answer below, which uses JunitXml.TestLogger by Shane Rich.

I couldn't get this to work using the syntax provided in the answer of Eric Erhardt.
Using the TRX Logger examples here I was able to recreate the correct syntax.
dotnet test --logger:"trx;LogFileName=C:\Temp\TestResults.xml" MyLibraryToTest.dll
$ dotnet test --logger:"trx;LogFileName=C:\Temp\TestResults.xml" MyLibraryToTest.dll
Microsoft (R) Test Execution Command Line Tool Version 16.8.1
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Starting ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761}) on port 51459
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Results File: C:\Temp\TestResults.xml
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 7 s - MyLibraryToTest.dll (net5.0)
You can see all the
dotnet test
options by executingdotnet test --help
. One of the options is-l, --logger
, which gives some great information:That support link https://aka.ms/vstest-report, has the full information.
So to answer your specific question, you can say
dotnet test -l:trx;LogFileName=C:\temp\TestOutput.xml
To publish the results to a particular directory.
Another option is setting MSBuild properties in your test.csproj:
Which tells the logger to put the file in the
C:\temp
directory.