How to write to Console.Out during execution of an MSTest test

后端 未结 5 1582
谎友^
谎友^ 2020-11-28 03:25

Context:
We have some users reporting issues with a file upload feature in our web application. It only happens occasionally and without any sp

5条回答
  •  日久生厌
    2020-11-28 04:13

    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");
    

提交回复
热议问题