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

前端 未结 12 1094
长情又很酷
长情又很酷 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:12

    I have an easier solution (that I used myself recently, for a host of lazy reasons). Add this method to the class you are working in:

    public static void DumbDebug(string message)
    {
        File.WriteAllText(@"C:\AdHocConsole\" + message + ".txt", "this is really dumb. I wish Microsoft had more obvious solutions to its solutions problems.");
    }
    

    Then...open up the directory AdHocConsole, and order by created time. Make sure when you add your 'print statements'. They are distinct though, else there will be juggling.

提交回复
热议问题