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

前端 未结 4 362
暖寄归人
暖寄归人 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:31

    The literal answer would be that you would use Console.SetOut before calling the class under test to direct stdout into a memoryStream or similar, whose contents you can later inspect.

    The better answer would be to use a mocking framework, like Rhino Mocks to create a concrete instance of your abstract class, with an expectation set that the DrawXXShape method would be called.

提交回复
热议问题