Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dotnet test / dotnet vstest and console output on success. https://github.com/xunit/xunit/issues/1141
public class UnitTest1
{
public UnitTest1(ITestOutputHelper output)
{
var listener = new TestTraceListener(output);
Trace.Listeners.Add(listener);
_output = listener;
}
class TestTraceListener : TraceListener
{
ITestOutputHelper _output;
public TestTraceListener(ITestOutputHelper output) { _output = output; }
public override void Write(string message)
{
Console.WriteLine(message); // success message when you want show
_output.WriteLine(message);
}
public override void WriteLine(string message)
{
Console.WriteLine(message); // success message when you want show
_output.WriteLine(message);
}
}
private readonly TestTraceListener _output;
// Your Test
[Theory("hoge")]
public async ValueTask Test1(string actual)
{
_output.WriteLine("Any message you want to show on `dotnet test`");
Assert.Equal("hoge", actual)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.