简体   繁体   English

在 MSTEST 期间将实时 output 写入 window 或文本窗格

[英]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.我正在使用Trace工具进行日志记录,并且我希望日志 output在测试期间出现在 Visual Studio 中某处的 window 或文本窗格中。

What is the simplest way to achieve this?实现这一目标的最简单方法是什么? Debug.Print() statements only show up at the end of the test. Debug.Print()语句仅在测试结束时显示。 Trying to open a console window seems like a non-starter (it's not a console application, and I can't seem to get the correct handle).试图打开一个控制台 window 似乎是一个非首发(它不是一个控制台应用程序,我似乎无法获得正确的句柄)。

I'm using my own static Log class, so I don't have to use Trace to do this.我正在使用我自己的 static 日志 class,所以我不必使用 Trace 来执行此操作。

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.如果您在调试模式下运行,则将由 Visual Studio Output Window 捕获,这不应取决于测试执行阶段(测试的开始/结束),因此应尽快在调试 Z78E6221F6393D13566681 中跟踪它。

Such kind of output also could be captured and filtered by tools like DbgView此类 output 也可以通过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)我已经创建了 MSTest 测试并能够在 Debug Window 中观察每条新行是如何每秒出现的:(在 output window 中,您可以选择Build/Debug Debug选项)

[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.必须从Test\Debug\Tests In Current Context菜单运行测试。 The Run Tests option from the right-click context menu will not work.右键单击上下文菜单中的“运行测试”选项将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM