How can I write output from a unit test?

后端 未结 15 989
误落风尘
误落风尘 2020-11-28 20:56

Any call in my unit tests to either Debug.Write(line) or Console.Write(Line) simply gets skipped over while debugging and the output is never print

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 21:48

    I was also trying to get Debug or Trace or Console or TestContext to work in unit testing.

    None of these methods would appear to work or show output in the output window:

        Trace.WriteLine("test trace");
        Debug.WriteLine("test debug");
        TestContext.WriteLine("test context");
        Console.WriteLine("test console");
    

    Visual Studio 2012 and greater

    (from comments) In Visual Studio 2012, there is no icon. Instead, there is a link in the test results called Output. If you click on the link, you see all of the WriteLine.

    Prior to Visual Studio 2012

    I then noticed in my Test Results window, after running the test, next to the little success green circle, there is another icon. I doubled clicked it. It was my test results, and it included all of the types of writelines above.

提交回复
热议问题