Can I write into the console in a unit test? If yes, why doesn't the console window open?

前端 未结 12 1073
长情又很酷
长情又很酷 2020-12-04 13:32

I have a test project in Visual Studio. I use Microsoft.VisualStudio.TestTools.UnitTesting.

I add this line in one of my unit tests:

Console.W         


        
12条回答
  •  粉色の甜心
    2020-12-04 14:18

    IMHO, output messages are relevant only for failed test cases in most cases. I made up the below format, and you can make your own too. This is displayed in the Visual Studio Test Explorer Window itself.

    How can we throw this message in the Visual Studio Test Explorer Window?

    Sample code like this should work:

    if(test_condition_fails)
        Assert.Fail(@"Test Type: Positive/Negative.
                    Mock Properties: someclass.propertyOne: True
                    someclass.propertyTwo: True
                    Test Properties: someclass.testPropertyOne: True
                    someclass.testPropertyOne: False
                    Reason for Failure: The Mail was not sent on Success Task completion.");
    

    You can have a separate class dedicated to this for you.

提交回复
热议问题