I just started testing xUnit.net, but it doesn’t seem to capture any output (Console, Debug, Trace), as I would have expected.
Is that possible? I am using a sample .NET 4.0 class-library with xUnit.net 1.8.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In general, it’s a bad road to go down to be reliant on logging and tests. The pass/fail should be the outcome of the tests. And they simply shouldn’t get to the stage where there’s enough stuff going on that looking at a trace will be necessary.
The
xunit.gui.exeshows Console and Trace output,xunit.console.exedoes not. If it’s important, you could hook up a TraceListener which redirects to a file by making appropriate standard .NET config entries (Theres’ aFileWriterTraceListenerwhich you should be able to hook in if you google it).UPDATE: As discussed in his blog post, Damian Hickey has a good example of a possible substitute – wiring logging to the xUnit 2
ITestOutputHelperas demonstrated in https://github.com/damianh/CapturingLogOutputWithXunit2AndParallelTests/blob/master/src/Lib.Tests/Tests.csUPDATE 2: In some cases, one can add logging and feed it to the
ITestOutputHelperwithout involvingLogContextby using a simple adapter as follows (I only have it in F#, sorry):The difference with this approach vs using the log context is that logging to the global [contextualized] Serilog
Loggerwill not get picked up.