How to get console output in Visual Studio 2012 Unit Tests

孤街浪徒 提交于 2019-12-06 16:46:35

问题


I have a managed C++ unit test in VS 2012. The test runs fine and I can verify that a loop with multiple cout calls is executed.

However when I look at the test explorer the test is marked as passed but there is no hyper link for the output as I am used to for c# projects.

The code at the end of my test is

for (int i = 0; i < 4; i++)
{
    cout << parameters[i];
    cout << endl;
}

which I can verify runs as I step through it in the debugger. I have also tried with cerr but no difference.


回答1:


You can use Debug::WriteLine() (in the System::Diagnostics namespace) or Console::WriteLine() to write output to the Visual Studio 2012 console.

Code for the test (note that the System::Diagnostics namespace is declared elsewhere).

The test result view.

After clicking the "Output" link:

It is not using std::cout, but hopefully this will do what you need it to do.




回答2:


For me seems to work using:

Logger::WriteMessage("What ever message");

After you run the test you can see the output in the Test Explorer window by clicking on output




回答3:


I don't know that I can give you a definitive answer, but I may be able to provide a clue.

In my older code that needed to get output to the console window during a custom build step, I used the following lines:

_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);

There is a description at http://msdn.microsoft.com/en-us/library/8hyw4sy7(v=vs.71).aspx for _CrtDbgReport.

For me, this made the output from my managed C++ show up through the build output window. Hope it can help you with Unit Testing.




回答4:


According to Microsoft connect trx and test results are deprecated

:(

http://connect.microsoft.com/VisualStudio/feedback/details/750184/test-results-window-does-not-show-test-results



来源:https://stackoverflow.com/questions/16815804/how-to-get-console-output-in-visual-studio-2012-unit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!