Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No output in VS Code when running tests

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");
    }
}
like image 824
Johan Avatar asked Dec 19 '25 02:12

Johan


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.

Note: As of early 2024 with the latest standard C# extensions from Microsoft, the source to select in the dropdown of the OUTPUT tab is called "C# Dev Kit - Test Explorer"

like image 148
Bartek Muszynski Avatar answered Dec 20 '25 14:12

Bartek Muszynski