Jon*_*han 12 googletest visual-studio
有没有办法在Visual Studio中查看Google测试结果?如果有,怎么样?
我正在使用Google Test 1.5.0和Visual Studio 2010
到目前为止,我一直在从命令行使用Google Test.
我已经在其他IDE(eclipse ......)上看到了这样的集成,但在VS中还没有
小智 7
看看GoogleTestAddin - 我认为这就是你想要的.
引自CodePlex描述:
GoogleTestAddin是Visual Studio 2008和2010的加载项.
通过选择它们,可以更轻松地执行/调试googletest函数.
您将不再需要将测试应用程序的命令参数设置为仅执行指定的函数或测试.
googletest输出被重定向到Visual Studio输出窗口.在失败的测试中,您可以通过双击错误消息轻松跳转到代码.
有一种非常简单的方法可以使用googletest的输出并行进行单元测试.
简而言之,您可以创建自己的Printer类,将结果直接输出到VisualStudio的输出窗口.这种方式似乎比其他方式更灵活,因为您可以控制结果的内容(格式,详细信息等)和目的地.你可以在你的main()功能中做到这一点.您可以一次使用多个打印机.您可以通过在失败的测试上双击错误消息来跳转到代码.
这些是执行此操作的步骤:
::testing::EmptyTestEventListener
类的类.OutputDebugString()
功能而不是printf().RUN_ALL_TESTS()调用之前,创建一个类的实例并将其链接到gtest的侦听器列表.您的Printer类可能如下所示:
// Provides alternative output mode which produces minimal amount of
// information about tests.
class TersePrinter : public EmptyTestEventListener {
void outDebugStringA (const char *format, ...)
{
va_list args;
va_start( args, format );
int len = _vscprintf( format, args ) + 1;
char *str = new char[len * sizeof(char)];
vsprintf(str, format, args );
OutputDebugStringA(str);
delete [] str;
}
// Called after all test activities have ended.
virtual void OnTestProgramEnd(const UnitTest& unit_test) {
outDebugStringA("TEST %s\n", unit_test.Passed() ? "PASSED" : "FAILED");
}
// Called before a test starts.
virtual void OnTestStart(const TestInfo& test_info) {
outDebugStringA(
"*** Test %s.%s starting.\n",
test_info.test_case_name(),
test_info.name());
}
// Called after a failed assertion or a SUCCEED() invocation.
virtual void OnTestPartResult(const TestPartResult& test_part_result) {
outDebugStringA(
"%s in %s:%d\n%s\n",
test_part_result.failed() ? "*** Failure" : "Success",
test_part_result.file_name(),
test_part_result.line_number(),
test_part_result.summary());
}
// Called after a test ends.
virtual void OnTestEnd(const TestInfo& test_info) {
outDebugStringA(
"*** Test %s.%s ending.\n",
test_info.test_case_name(),
test_info.name());
}
}; // class TersePrinter
Run Code Online (Sandbox Code Playgroud)
将打印机链接到侦听器列表:
UnitTest& unit_test = *UnitTest::GetInstance();
TestEventListeners& listeners = unit_test.listeners();
listeners.Append(new TersePrinter);
Run Code Online (Sandbox Code Playgroud)
该方法是在所描述的样品#9从所述Googletest样品.
您可以使用后期构建事件.以下是指南:http:
//leefw.wordpress.com/2010/11/17/google-test-gtest-setup-with-microsoft-visual-studio-2008-c/
您还可以在Visual Studio的"工具"菜单中配置"外部工具",并使用它来运行项目的目标路径.(提示:创建工具栏菜单项以使其更容易调用)
对于Visual Studio 2012,还有一个扩展,在Visual Studio中为Google Test提供测试适配器(因此与Visual Studios Test Explorer集成): Google Test Adapter
| 归档时间: |
|
| 查看次数: |
8000 次 |
| 最近记录: |