George Mauer
George Mauer

Reputation: 122182

When running `dotnet test` show output of the `dotnet vstest` output sink

Edit: Below is the former question originally posted with the title

xunit show ITestOutputHelper output when run in the console

After investigation (see comments), the question is still very much relevant and in need of an answer but it seems that it should be addressed to the vstest framework and around output sinks rather than xunit.

The specific question now is: When something is written to the dotnet vstest output sink, how do I get it to display when running dotnet test from the command line. Specifically I want to be able to set up a watcher with dotnet watch to run tests continuously and I care more about output than results (I am using this less as a testing system and more as a development notebook). And I don't want to be limited to visual studio or vscode.

Original Question:

In my test class I have

    [Fact]
    public void Test() {

       output.WriteLine("WHATEVER");

    }
    readonly ITestOutputHelper output;

    public GroceryTests(ITestOutputHelper output) => this.output = output;

When I run this through the vscode in-editor integration I can see the output in the Output pane. When I run it via dotnet test I do not. How do I get this output to show up via console?

Upvotes: 37

Views: 26326

Answers (2)

bypasswer
bypasswer

Reputation: 231

@weichch's answer works for me even without any specific log sink usage. The command dotnet test -l "console;verbosity=detailed" is showing me all the Console.WriteLines of my tests just fine. And doesn't clutter much.

Note that you can add --filter="Name=<MethodName>" to the command to run tests with such name.

My tests all have attribute [NonParallelizable].
Using dotnet 5

The command is also mentioned in this answer at github.

Upvotes: 23

weichch
weichch

Reputation: 10055

Just to share what worked for me (I am no expert of vstest sink stuff, so probably can't answer deeper questions):

I have a simple test like this:

public class UnitTest1
{
    private readonly ITestOutputHelper _output;

    public UnitTest1(ITestOutputHelper output)
    {
        _output = output;
    }

    [Fact]
    public void Test1()
    {
        _output.WriteLine("My message.");
    }
}

So if I watch / run this test in console:

dotnet watch test --logger:"console;verbosity=detailed"

I see output like:

  V XUnitTestProject1.UnitTest1.Test1 [5ms]
  Standard Output Messages:
 My message.

I am using .NET Core SDK 3.1.201.

Upvotes: 55

Related Questions