Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish results using dotnet test command

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

like image 949
Raghavendra Bankapur Avatar asked Apr 19 '18 09:04

Raghavendra Bankapur


People also ask

How do I publish a Dot Net command?

To make publish output go to separate folders for each project, specify a relative path by using the msbuild PublishDir property instead of the --output option. For example, dotnet publish -p:PublishDir=. \publish sends publish output for each project to a publish folder under the folder that contains the project file.

What is dotnet test command?

The dotnet test command is used to execute unit tests in a given solution. The dotnet test command builds the solution and runs a test host application for each test project in the solution.

Does dotnet use Vstest?

The dotnet vstest command is superseded by dotnet test , which can now be used to run assemblies.

How do I run a .NET core test?

Let us open the FirstApp solution in Visual Studio. You can see that it has only two projects and you will not be able to see the test project because we haven't added that project in our solution. Let us add a folder first and call it test. Right-click on the test folder.


2 Answers

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.

like image 93
Eric Erhardt Avatar answered Sep 19 '22 08:09

Eric Erhardt


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" 
like image 28
Andre Albuquerque Avatar answered Sep 18 '22 08:09

Andre Albuquerque