How can I output some debug data during an xunit test?

Pure Krome's Avatar

Pure Krome

28 Jun, 2015 08:19 AM

Hi Fedor,

I've got some xunit tests that pass on my localhost but fail on AV. So - trying to figure this out .. so I'm trying to dump some data to the console out (get variable data, etc).

How can I do that in some really boring standard xunit 2.0 test?

eg.

[Fact]
public void GivenABoringTest_Foo_DoesSomething()
{
    // Arrange.

    // Act.
    var foo = PewPew();

    // Assert.
    Console.WriteLine(foo.Name);
}

I've tried Console.WriteLine(..); and Debug.WriteLine(..); but I can't see the info in the AV Latest Build -> Console (or any of those 4 tabs).

Hmmm.. Suggestions pwease?

  1. Support Staff 1 Posted by Feodor Fitsner on 28 Jun, 2015 05:22 PM

    Feodor Fitsner's Avatar

    Console.WriteLine() should have supposed to work. Output should be collected and shown along with test I test results page. If not how does runner suppress it?

    You can write/append to file and then include it to artifacts thought it's not as elegant.

    Btw, try Trace.* methods.

    - Feodor

  2. 2 Posted by Pure Krome on 30 Jun, 2015 12:32 PM

    Pure Krome's Avatar

    Hi Feodor.

    Yeah, I would have thought so too.

    Here's the public AV project: https://ci.appveyor.com/project/PureKrome/nlog-bugsnag
    I can't find any logged messages.

    Here's the code (from an OSS project) which does the output lines: https://github.com/PureKrome/NLog.Bugsnag/blob/dev/Code/Tests/BugSn...

    Not sure what's going wrong here - as in, why it's not printing the debug text.

    (note: i'm not setting the Configuration (eg. release or debug) and it looks like it is defaulting to Debug:

    ValidateSolutionConfiguration:
      Building solution configuration "Debug|Any CPU".
    
  3. Support Staff 3 Posted by Feodor Fitsner on 30 Jun, 2015 05:10 PM

    Feodor Fitsner's Avatar

    But it actually fails on this line: https://github.com/PureKrome/NLog.Bugsnag/blob/dev/Code/Tests/BugSn... - error is null.

  4. Support Staff 4 Posted by Feodor Fitsner on 30 Jun, 2015 05:16 PM

    Feodor Fitsner's Avatar
  5. 5 Posted by Pure Krome on 05 Jul, 2015 09:45 AM

    Pure Krome's Avatar

    Hi Feodor - yep. confirmed. Problem was me reading code / error messages late at night.

    For anyone else reading this, if you wish to redirect Debug.WriteLine .. etc to the Console.Out .. you can use this (and this can also be re-written in a config file, I believe)...

    TraceListener[] listeners = {
            new TextWriterTraceListener(Console.Out)
        };
        Debug.Listeners.AddRange(listeners);
    
  6. Pure Krome closed this discussion on 05 Jul, 2015 09:45 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac