专栏首页Eureka伽罗的技术时光轴How to use Google Test for C++ in Visual Studio

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

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++

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • bochs compile 编译

    The standard compile uses the configure script, but the Windows platform cannot ...

    战神伽罗
  • gcc x64 asm 内联汇编尝试

    asm volatile(assembler template : output : input : clobber);

    战神伽罗
  • How to Implement an MI Provider

    The Windows Software Development Kit (SDK) for Windows 8 contains headers, libra...

    战神伽罗
  • 聊聊flink的SourceFunction

    flink-streaming-java_2.11-1.6.2-sources.jar!/org/apache/flink/streaming/api/func...

    codecraft
  • bochs compile 编译

    The standard compile uses the configure script, but the Windows platform cannot ...

    战神伽罗
  • 5 Postmodel Workflow

    This chapter will cover the following recipes:这章将包含以下部分:

    到不了的都叫做远方
  • Classifying documents with Naïve Bayes使用朴素贝叶斯分类文本

    Naïve Bayes is a really interesting model. It's somewhat similar to k-NN in the ...

    到不了的都叫做远方
  • LSTM生成尼采风格文章

    github地址 使用循环神经网络生成序列文本数据。循环神经网络可以用来生成音乐、图像作品、语音、对话系统对话等等。

    用户1631856
  • 0x8 Python教程:Whois自动化

    本教程将演示一些功夫与Team Cymru的Python whois模块。在infosec中的攻击和防御角色中,你需要做很多whois查看,这个python模块...

    重生信息安全
  • 面子:人脸识别审计的伦理问题研究(CS CY )

    尽管披露有偏见的绩效是必要的,但出于好意的算法审计尝试可能会对这些措施旨在保护的人群造成伤害。在审核面部识别等生物识别系统时,这种担忧甚至更为突出。在这些系统中...

    用户6853689

扫码关注云+社区

领取腾讯云代金券