While trying to automate my MSTest based tests using dotnet test command I am experiencing an issue where only the outputs of the last test project run (in the solution) are written to the specified logger output

I have tried running the command line is as follows :

dotnet test $ProjectSln --results-directory ./Reports -l "trx;LogFileName=$($ReportFile)" "/p:GeneratePackageOnBuild=False;Configuration=Release;Platform=Any CPU;SolutionDir=${RootDir}"# "-verbosity:minimal"

but that produces an xml file containing only outputs of a single project tests.

Is there any way to make the command log outputs of all tests to a single file?

1

There are 1 best solutions below

1
Greg Burghardt On

Since the command executes tests in multiple projects, use the LogFilePrefix argument instead of LogFileName:

dotnet test $ProjectSln --results-directory ./Reports -l "trx;LogFilePrefix=$($ReportFile)" "/p:GeneratePackageOnBuild=False;Configuration=Release;Platform=Any CPU;SolutionDir=${RootDir}"
#                                                             ^^^^^^^^^^^^^

Here is the same command formatted on multiple lines if that is easier to read:

dotnet test $ProjectSln `
            --results-directory ./Reports `
            -l "trx;LogFilePrefix=$($ReportFile)" `
            "/p:GeneratePackageOnBuild=False;Configuration=Release;Platform=Any CPU;SolutionDir=${RootDir}"

The Microsoft documentation has a number of examples you can reference.