• <small id='zCfgt'></small><noframes id='zCfgt'>

      <i id='zCfgt'><tr id='zCfgt'><dt id='zCfgt'><q id='zCfgt'><span id='zCfgt'><b id='zCfgt'><form id='zCfgt'><ins id='zCfgt'></ins><ul id='zCfgt'></ul><sub id='zCfgt'></sub></form><legend id='zCfgt'></legend><bdo id='zCfgt'><pre id='zCfgt'><center id='zCfgt'></center></pre></bdo></b><th id='zCfgt'></th></span></q></dt></tr></i><div id='zCfgt'><tfoot id='zCfgt'></tfoot><dl id='zCfgt'><fieldset id='zCfgt'></fieldset></dl></div>

    1. <tfoot id='zCfgt'></tfoot>

          <bdo id='zCfgt'></bdo><ul id='zCfgt'></ul>

        <legend id='zCfgt'><style id='zCfgt'><dir id='zCfgt'><q id='zCfgt'></q></dir></style></legend>
      1. 如何在执行 MSTest 测试期间写入 Console.Out

        时间:2023-08-26

              <bdo id='4hWhi'></bdo><ul id='4hWhi'></ul>

              • <small id='4hWhi'></small><noframes id='4hWhi'>

                  <tbody id='4hWhi'></tbody>
                1. <i id='4hWhi'><tr id='4hWhi'><dt id='4hWhi'><q id='4hWhi'><span id='4hWhi'><b id='4hWhi'><form id='4hWhi'><ins id='4hWhi'></ins><ul id='4hWhi'></ul><sub id='4hWhi'></sub></form><legend id='4hWhi'></legend><bdo id='4hWhi'><pre id='4hWhi'><center id='4hWhi'></center></pre></bdo></b><th id='4hWhi'></th></span></q></dt></tr></i><div id='4hWhi'><tfoot id='4hWhi'></tfoot><dl id='4hWhi'><fieldset id='4hWhi'></fieldset></dl></div>
                2. <tfoot id='4hWhi'></tfoot>
                  <legend id='4hWhi'><style id='4hWhi'><dir id='4hWhi'><q id='4hWhi'></q></dir></style></legend>
                  本文介绍了如何在执行 MSTest 测试期间写入 Console.Out的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  上下文:
                  我们有一些用户报告我们的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                      <tbody id='egvqD'></tbody>
                    <tfoot id='egvqD'></tfoot>

                    <small id='egvqD'></small><noframes id='egvqD'>

                      <bdo id='egvqD'></bdo><ul id='egvqD'></ul>

                      <i id='egvqD'><tr id='egvqD'><dt id='egvqD'><q id='egvqD'><span id='egvqD'><b id='egvqD'><form id='egvqD'><ins id='egvqD'></ins><ul id='egvqD'></ul><sub id='egvqD'></sub></form><legend id='egvqD'></legend><bdo id='egvqD'><pre id='egvqD'><center id='egvqD'></center></pre></bdo></b><th id='egvqD'></th></span></q></dt></tr></i><div id='egvqD'><tfoot id='egvqD'></tfoot><dl id='egvqD'><fieldset id='egvqD'></fieldset></dl></div>

                      1. <legend id='egvqD'><style id='egvqD'><dir id='egvqD'><q id='egvqD'></q></dir></style></legend>