上下文:
我们有一些用户报告我们的 Web 应用程序中的文件上传功能存在问题.它只是偶尔发生,没有任何特殊模式.很长一段时间以来,我们一直在尝试解决这个问题,在我们认为可能有帮助的任何地方添加调试信息,爬取日志等,但我们无法重现或解决它.
问题:
我现在试图通过使用 MSTest 和 WatiN 来重复这个应该失败很多次(几百次)的操作.为了了解测试在循环中的进展情况,我想打印如下内容:
Console.WriteLine(String.Format("上传的文件,尝试 {0} of {1}", i, maxUploads));
但这不会出现在输出"窗口中.现在我知道您将在测试结果中获得控制台输出(以及您从 Debug.Writeline
等输出的内容),但这在 after 之前不可用测试已经结束.而且由于我的数百次重复测试可能需要相当长的时间,我想知道它已经走了多远.
问题:
有没有办法在测试执行期间在输出窗口中获取控制台输出?
没有出现控制台输出是因为后端代码没有在测试的上下文中运行.
您最好使用 Trace.WriteLine
(在 System.Diagnostics 中),然后添加一个写入文件的跟踪侦听器.
来自 MSDN 的这个主题 展示了一种实现方式.
<小时>根据 Marty Neal 和 Dave Anderson 的评论:
<块引用>使用系统;使用 System.Diagnostics;...Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));//或 Trace.Listeners.Add(new ConsoleTraceListener());Trace.WriteLine("Hello World");
Context:
We have some users reporting issues with a file upload feature in our web application. It only happens occasionally and without any special pattern. We have been trying to figure it out for a long time, adding debug information anywhere we can think it might help, crawling the logs etc, but we have not been able to reproduce or figure it out.
Problem:
I'm now trying to reproduce this by using MSTest and WatiN to repeat the operation that is supposed to fail a large number of times (several hundreds). Just to have a clue about how far in the loop the test has gotten, I want to print something like:
Console.WriteLine(String.Format("Uploaded file, attempt {0} of {1}", i, maxUploads));
This does however not appear in the Output window. Now I know that you'll get the console output in the test results (as well as what you output from Debug.Writeline
etc), but this is not available until after the test has finished. And since my test with hundreds of repetitions could take quite some time, I'd like to know how far it has gotten.
Question:
Is there a way I can get the console output in the Output window during test execution?
The Console output is not appearing is because the backend code is not running in the context of the test.
You're probably better off using Trace.WriteLine
(In System.Diagnostics) and then adding a trace listener which writes to a file.
This topic from MSDN shows a way of doing this.
According to Marty Neal's and Dave Anderson's comments:
using System; using System.Diagnostics; ... Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); // or Trace.Listeners.Add(new ConsoleTraceListener()); Trace.WriteLine("Hello World");
这篇关于如何在执行 MSTest 测试期间写入 Console.Out的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!