0

Currently I am executing some test in my dll via command line like so

dotnet test UnitTest123/bin/Debug/UnitTest123.dll --logger html

After executing I get my results in my TestResults folder where my project is in my local machine.. I want to give my report some meaning full name like UnitTest123 but I get TestResult_MachineName-WS102_20201008_184559

Another Thing I wanted to know was how can I log to the report.. example if I have to log a message so it will show in the report how can I do this? I have tried TestContext but it did not work..

Thanks for any help :)

Jones Jones
  • 51
  • 1
  • 5

1 Answers1

1

As far as I can see, you can't change the file name for the html report, only the folder:

dotnet test -l:html -r htmlresultsfolder

Using non html format you can do something like this:

dotnet test -l:trx;LogFileName=C:\temp\TestOutput.xml

Or:

dotnet test --logger "console;verbosity=detailed" > WHATEVER_FILENAME_YOUWANT.log

Alternatively (based on the fact you said you're using NUnit), I found (but never used) this logger: https://github.com/spekt/nunit.testlogger Which seems to let you specify the output file name:

dotnet test --test-adapter-path:. --logger:"nunit;LogFilePath=test-result.xml"

Without seeing your cude, I think you can use this to capture output: https://xunit.net/docs/capturing-output

using Xunit;
using Xunit.Abstractions;

public class MyTestClass
{
    private readonly ITestOutputHelper output;

    public MyTestClass(ITestOutputHelper output)
    {
        this.output = output;
    }

    [Fact]
    public void MyTest()
    {
        var temp = "my class!";
        output.WriteLine("This is output from {0}", temp);
    }
}
dtroy
  • 1,187
  • 3
  • 14
  • 21
  • @jones-jones: Check this out for printing out in NUnit: https://stackoverflow.com/a/35041516/36777 – dtroy Oct 09 '20 at 03:58