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");
}
}
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With