我在Visual Studio中有一个测试项目.我使用Microsoft.VisualStudio.TestTools.UnitTesting.
我在我的一个单元测试中添加了这一行:
Console.WriteLine("Some foo was very angry with boo");
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,测试通过,但控制台窗口根本没有打开.
有没有办法让控制台窗口可以通过单元测试进行交互?
在Java中,您可以使用System.out.println(message)将消息打印到输出窗口.
Visual Studio中的等价物是什么?
我知道当我处于调试模式时,我可以使用它在输出窗口中查看消息:
Debug.WriteLine("Debug : User_Id = "+Session["User_Id"]);
System.Diagnostics.Trace.WriteLine("Debug : User_Id = "+Session["User_Id"]);
Run Code Online (Sandbox Code Playgroud)
如果不在Visual Studio中进行调试,如何才能完成此操作?
简而言之:Console.WriteLine在VS 2015中运行正常,但它在VS 2017中不再起作用了.
详细说明:我有一些使用Console.Write的VB代码可以在VS 2015中输出ok,即使配置为使用Start Debugging启动的Release(与Debug相比)(与Start Without Debugging相反).
今天我升级到了VS 2017(社区版),但是Console.Write在与VS 2015相同的条件下不再工作了.
也许我过去在VS 2015中做了一些配置,但我不记得了.
有人可以帮我如何在相同条件下将Console.Write输出到Output Window(使用Start Debugging启动Release配置).
Obs:当你处于Debug配置时,Debug.Writeline工作正常(输出到Output Window).当您处于Release配置时,Debug.Writeline,即使您使用Start Debugging启动,也不会输出(到Output Window).需求(以及问题)是在Release配置中的Start Debugging的上下文中.
与“写入 Visual Studio 的输出窗口? ”中所问的完全一样,但是解决了剩余的问题——
我假设如果我在没有调试(ctrl-f5)的情况下开始,就没有办法写入输出,对吗?– previous_developer 2012 年 2 月 27 日
Debug.WriteLine() 仅在 Debug 中运行时才有效。这意味着使用 F5 而不是 CTRL-F5 运行它。– kirk.burleson 2013 年 7 月 15 日
然而,事实并非如此,因为:
刚刚在这里运行了一个小应用程序,对我来说很好用。也许您的环境中存在小故障?– Bhargav Bhat 2012 年 2 月 27 日
在正常运行期间,我可以在 Visual Studio 输出窗口中看到一些信息打印:
[1/10/2018 11:56:25 AM Informational] ------ Run test started ------
[1/10/2018 11:56:26 AM Informational] NUnit Adapter 3.9.0.0: Test execution started
[1/10/2018 11:56:26 AM Informational] Running selected tests in ...\Demo.dll
[1/10/2018 11:56:26 AM …Run Code Online (Sandbox Code Playgroud)