14

I am trying to log some information while the unit test is running in MS Unit Testing Framework VS 2010.

I tried Trace.WriteLine, Console.WriteLine and Debug.WriteLine but I am not able to see the output in the output window.

Any idea how to do it? Thanks in advance

2 Answers 2

16

Make sure your test class contains the following:

private TestContext testContextInstance;

/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext
{
    get
    {
        return testContextInstance;
    }
    set
    {
        testContextInstance = value;
    }
}

Then you can call:

this.testContextInstance.WriteLine("Hello World");
Sign up to request clarification or add additional context in comments.

2 Comments

As mentioned below: this is not visible in the 'output' window, but in the "test results" window.
Classic Microsoft API LOLs.
11

The output from the test case is not visible in visual studio's output window. Rather it is visible in the "test results window". In the test result window, you should double click on the result of the test case (Passed/addTest row in the picture) for which you want to see the output and there you will see the all your writeLines.

alt text

2 Comments

Thanks tjRobinson and Assem Bansal. This is what I was looking for
And in Visual Studio 2013 it's under "Output" for each test in the Test Explorer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.