No output in VS Code when running tests

Viewed 824

I'm running an XUnit test-ptoject in VS Code with the .NET Core Test Explorer extension. I'm trying to write output during the tests but nothing is working. I've tried writing output in different ways, but can't see any output anywhere. Has anyone managed to see output in vs code somehow while running tests?

Here is a small example class:

using Xunit;
using Xunit.Abstractions;
using System.Diagnostics;

public class TestClass
{

    private ITestOutputHelper _output;


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

    [Fact]
    public void Test2()
    {
        _output.WriteLine("Hello");
        Debug.WriteLine("Hello");
        Console.WriteLine("Hello");
    }
}
1 Answers

Output only shows if the test fails.

If you need to to see your output, you can (temporarily) add this line at the end of the test:

Assert.False(true, "Fail on purpose");

If you're running in VS Code, the test output will be visible in the "OUTPUT" tab when you set the source to "Test Explorer (Test runner output)" in the drop-down on the right.

Related