开发者

Writing real-time output to a window or text pane during MSTEST

I'm using the Trace facility to do logging, and I'd like the log output to appear in a window or text pane somewhere in Visual Studio during the test.

What is the simplest way to achieve this? Debug.Print() statements only show up at the end of the test. Trying to open a console window seems like a non-starter (it's not a conso开发者_StackOverflowle application, and I can't seem to get the correct handle).

I'm using my own static Log class, so I don't have to use Trace to do this.


System.Diagnostics.Debug.WriteLine()

will be captured by the Visual Studio Output Window if you run in Debug mode and this should not depend on test execution stage (start/end of a test), so it should be tracked in debug output as soon as executed.

Such kind of output also could be captured and filtered by tools like DbgView

EDIT: answer to comment

I've created MSTest test and able to observe in Debug Window how each new line comes up per each second: (In the output window you can choose between Build/Debug, please ensure you've selected Debug option in drop down list)

[TestMethod]
public void TestMethod1()
{
    int i = 10;

    while(i-- > 0)
    {
        Thread.Sleep(1000);
        Debug.WriteLine("Step #" + i);
    }
}

The test must be run from the Test\Debug\Tests In Current Context menu. The Run Tests option from the right-click context menu will not work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜