如何在Visual Studio 2012单元测试中获取控制台输出 [英] How to get console output in Visual Studio 2012 Unit Tests
问题描述
我在VS 2012中有一个托管的C ++单元测试。该测试运行良好,我可以
验证是否执行了具有多个 cout
调用的循环。 / p>
但是,当我查看测试资源管理器时,测试标记为通过
,但是没有超级链接,因为我习惯了c#
个项目。
测试结束时的代码为
for(int i = 0; i< 4; i ++)
{
cout<参数[i];
cout<<恩德尔
}
在步入
时,我可以验证其运行调试器。我也尝试了
cerr
,但没有区别。
您可以使用Debug :: WriteLine()(在System :: Diagnostics命名空间中)或Console :: WriteLine()将输出写入Visual Studio 2012控制台。
测试代码(请注意,System :: Diagnostics命名空间在其他地方声明)。
测试结果视图。
单击输出链接后:
它未使用std :: cout,但希望这样做会满足您的需要
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.
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.
这篇关于如何在Visual Studio 2012单元测试中获取控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!