Unit Test Help. How do I test for a message output to console?

前端 未结 4 361
暖寄归人
暖寄归人 2021-01-17 21:55

I am a newbie to unit testing. How do I check the for console output? I have

namespace XXShapes
{
    public abstract class XXShape
    {
        public virt         


        
4条回答
  •  情话喂你
    2021-01-17 22:15

    I'm assuming that some other tests test for the drawing capabilities - If you now want to test that your classes write something in particular to the console, then you should abstract the idea of writing to the console.

    Create an interface with a WriteLine() method in it and inject instances that implement this interface into XXShapes. Your tests can inject mocks or stubs which can capture the strings that are written and test their contents in the tests.

提交回复
热议问题