Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created November 29, 2019 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/49e5b27e4c9b686fc55686971b3e5721 to your computer and use it in GitHub Desktop.
Save guitarrapc/49e5b27e4c9b686fc55686971b3e5721 to your computer and use it in GitHub Desktop.
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