How to write output from a unit test?

2019-01-16 07:11发布

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 printed. Calls to these functions from within classes I'm using work fine.

I understand that unit testing is meant to be automated, but I still would like to be able to output messages from a unit test.

13条回答
Evening l夕情丶
2楼-- · 2019-01-16 07:42

Solved with the following example:

public void CheckConsoleOutput()
    {
        Console.WriteLine("Hi Hi World");
        Trace.WriteLine("Trace Trace the World");
        Debug.WriteLine("Debug Debug WOrld");
        Assert.IsTrue(true);
    }

After running this test, under 'Test Passed', there is the option to view the output, which will bring up the output window.

查看更多
登录 后发表回答