21
votes

Can anyone tell me how to enable or get debug or console text output when running unit tests in a native (C++) test project in Visual Studio 2012?

Answer should not include the phrase, "use Google Test".

3
Will switching subsystem to console help? (project properties/linker/system) - Valentin Heinitz
Nice idea but alas, no. My code is outputting text using OutputDebugStringA and OutputDebugStringW. I guess I need to use some other library? - Robinson
I kind of solved it. The debug output shows in the debug output window if you right-click and choose `debug' on whichever test in the test explorer window. Otherwise it doesn't. - Robinson

3 Answers

24
votes

In the unit test code, you can use

Logger::WriteMessage("My message string");

and the message will appear in the Output window.

6
votes

Brian's answer is correct. Use

Logger::WriteMessage("some text");

and run the test normally (there is no need to debug). However, you also need to select "Tests" in the "Show output from" drop-down list at the top of the Output window.

VS 2013 Output window with Tests output selected

2
votes

The debug output shows in the debug output window if you right-click and choose `debug' on whichever test in the test explorer window. Otherwise it doesn't.