How to show Console.WriteLine (Standard Output ) in Test Detail Summary in Visual Studio 2022

1.5k Views Asked by At

I updated to Visual Studio 2022 recently (currently on version 17.1.6 on Windows 10) which has as a feature that it will show Standard Output or Console.WriteLine output in the Test Detail Summary. See Tips and Tricks - What's new in Visual Studio 2022 for Testing, which has this segment at 2:58
Console.WriteLine in test summary
enter image description here

Unfortunately when I am running tests via Test Explorer I am not getting that Standard Output section of the test summary. Is there a setting or an update I need to enable that feature?

I suppose I am basically asking how to do the opposite of what this question is asking: VS - Test Detail Summary Standard Output

1

There are 1 best solutions below

0
Torrents On BEST ANSWER

Unfortunately I haven't found a way to display the Standard Output section in the test results without a third party dependency. However if you are using XUnit, you can add a reference to XUnit.Abstractions, which supports an ITestOutputHelper. Using your OutputHelper you can write values directly to that Standard Output using its WriteLine method.

using Xunit;
using Xunit.Abstractions;

public class FileTester
{
    private readonly ITestOutputHelper output;

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

    [Fact]
    public async void ParsesFile()
    {
        // arrange
        var fileName = "TestFile";
        var outputFolder = Path.Combine("C:\Temp", fileName + ".txt");
        output.WriteLine(outputFolder);
        
        // etc.
    }
}

VS Test Detail Summary - Standard Output