Created
November 29, 2019 07:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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