Greg
Greg

Reputation: 34798

how can I view Console Output whilst my Unit Tests are running in Visual Studio 2008?

How can I view Console Output whilst my Unit Tests are running? I'm using the Visual Studio 2008 unit testing framework. So I know that after a test is finished I can go to the results page for the test and click on output, however I'm after a way that I can effectively watch the console output for tests as the unit tests are executed.

EDIT - Interested in a specific answer for VS out of the box (i.e. without having to buy a plugin)

Upvotes: 7

Views: 4499

Answers (3)

Mark Lakata
Mark Lakata

Reputation: 20818

A slight improvement on dodgy_coder's answer, that let's you use the variadic syntax of Console.WriteLine with a format statement with an arbitrary length list of objects after it.

    private void TestTrace(string message, params object[] args)
    {
        System.Diagnostics.Debug.WriteLine(String.Format(message,args));
        Console.Out.WriteLine(message,args);
    }

    void ex()
    {
        TestTrace("foo {0} {1}",bar,zzyzx);
    }

Note that you must run in Debug mode. In Release mode, the System.Diagnostics.Debug messages are suppressed.

Upvotes: 1

dodgy_coder
dodgy_coder

Reputation: 13033

You can use

System.Diagnostics.Debug.WriteLine("Message");

To output to the "Output" tab while the unit test is running.

If you are using Console.Out.WriteLine("Message") then this will only show up at the end of the test run, as you mentioned.

I have used the following to give me both runtime messages and the end of test result output:

private void TestTrace(string message)
{
    System.Diagnostics.Debug.WriteLine(message);
    Console.Out.WriteLine(message);
}

Upvotes: 4

ryber
ryber

Reputation: 4555

Use a TDD plug in like ReSharper orTestDriven.net

Upvotes: 0

Related Questions