Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get console output in Visual Studio 2012 Unit Tests

Tags:

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.

like image 980
bradgonesurfing Avatar asked May 29 '13 13:05

bradgonesurfing


People also ask

How do I show console output in Visual Studio?

Press F11 . Visual Studio calls the Console. WriteLine(String, Object, Object) method. The console window displays the formatted string.

How do I view test output in Visual Studio?

In the main menu of VS, choose View > Output, then within the Output pane, pick "Tests".

How do I run unit test from console?

run Visual Studio unit tests by using MSTest.exe, located at %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe in my case. using /testcontainer:Path\To\Your\TestProjectAssembly. dll to indicate where your tests are coded. You can specify multiple '/testcontainer' options if required.


1 Answers

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

The test result view.

enter image description here

After clicking the "Output" link:

enter image description here

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

like image 125
olen_garn Avatar answered Sep 25 '22 19:09

olen_garn