How to publish results using dotnet test command

2020-05-19 00:14发布

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

3条回答
相关推荐>>
2楼-- · 2020-05-19 00:35

In addition to Eric’s answer, you can also run dotnet xunit -xml output.xml

$ dotnet xunit --help
  ...
  Result formats: (optional, choose one or more)
  -xml <filename>        : output results to xUnit.net v2 XML file
  -xmlv1 <filename>      : [net4x only] output results to xUnit.net v1 XML file
  -nunit <filename>      : [net4x only] output results to NUnit v2.5 XML file
  -html <filename>       : [net4x only] output results to HTML file
...

http://xunit.github.io/docs/getting-started-dotnet-core

查看更多
放我归山
3楼-- · 2020-05-19 00:36

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"
查看更多
三岁会撩人
4楼-- · 2020-05-19 00:41

You can see all the dotnet test options by executing dotnet test --help. One of the options is -l, --logger, which gives some great information:

Specify a logger for test results.
Examples:
Log in trx format using a unqiue file name: --logger trx
Log in trx format using the specified file name: --logger "trx;LogFileName=<TestResults.trx>"
More info on logger arguments support:https://aka.ms/vstest-report

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:

<PropertyGroup>
  <VSTestLogger>trx</VSTestLogger>
  <VSTestResultsDirectory>C:\temp</VSTestResultsDirectory>
</PropertyGroup>

Which tells the logger to put the file in the C:\temp directory.

查看更多
登录 后发表回答