前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >How to use Google Test for C++ in Visual Studio

How to use Google Test for C++ in Visual Studio

作者头像
战神伽罗
发布2019-07-24 15:09:12
8250
发布2019-07-24 15:09:12
举报
文章被收录于专栏:Eureka的技术时光轴

In Visual Studio 2017 version 15.5 and later, Google Test is integrated into the Visual Studio IDE as a default component of the Desktop Develoment with C++ workload. To verify that it is installed on your machine, open the Visual Studio Installer and find Google Test under the list of workload components:

Add a Google Test Project to the solution

  1. In Solution Explorer, right click on the solution node and choose Add | New Project.
  2. In the left pane, choose Visual C++ | Test and then choose Google Test Project in the center pane.
  3. Give the test project a name and click OK.

Configure the test project

In the Test Project Configuration dialog that appears, you can choose the project you want to test. When you choose a project, Visual Studio adds a reference to the selected project. If you choose no project, then you need to manually add references to the project(s) you want to test. When choosing between static and dynamic linking to the Google Test binaries, the considerations are the same as for any C++ program. For more information, see DLLs in Visual C++.

Set additional options

From the main menu, choose Tools | Options | Test Adapter for Google Test to set additional options. See the Google Test documentation for more information about these settings.

Add include directives

In your test .cpp file, add any needed #include directives to make your program's types and functions visible to the test code. Typically, the program is up one level in the folder hierarchy. If you type #include "../" an IntelliSense window will appear and enable you to select the full path to the header file.

Write and run Tests

You are now ready to write and run Google Tests. See the Google Test Primer for information about the test macros. See Run unit tests with Test Explorer for information about discovering, running, and grouping your tests by using Test Explorer.

See also

Writing Unit Tests for C/C++

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Add a Google Test Project to the solution
  • Configure the test project
  • Set additional options
  • Add include directives
  • Write and run Tests
  • See also
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档