Google Test and Visual Studio

The contents of this post have been modified and moved to Computing on Plains. I am currently maintaining this post because there is a link to it from the documentation for Test Adapter for Google Test. I have submitted a pull request, but it has not yet been applied.


17 thoughts on “Google Test and Visual Studio

  1. Thanks for providing a tutorial on the Google Test Adapter! I hope it’s fine if I link this page from the Google Test Adapter homepage…

    Here’s a minor suggestion for improvement: the tutorial refers to the default naming scheme for test executables; this can however be overridden by configuring a test discovery regex, either through VS Options or (preferably) through a solution settings file to be shared via source control.

    One other note: Google Test Adapter is by now a complete rewrite (and much more feature complete), but has started as a C# port of the Google Test Runner by Markus Lindqvist.


    • Thank you for this contribution, it is very help. 2 remarks however:

      — I think step 2 has to be repeated as part of step 8 (otherwise the GTest includes are not available in the test project with the test code).
      I had a lot of compiler errors, which disappeared after asserting step 2 within step 8.

      — when building the solution (which contains those 3 projects) the following error occurs (copied from my output pane):
      “The following errors and warnings occured during test discovery (enable debug mode for more information):
      ERROR: Couldn’t find the msdia.dll to parse *.pdb files. You will not get any source locations for your tests.
      Warning: Could not find source location for test SquareTests.Square
      Cannot discover test extensions installed by NuGet. The NuGet service is not available. Tests may not be found due to missing test adapter extensions.”

      I installed GTA (succesfully) using Tools->Extensions and Updates… and the consecutive actions as stated above…..

      These errors/warnings do not seem to impede the test execution however….. the tests pass fine, debugger is launched….
      Are those errors relevant? What must be done to prevent them? What’s is missing in my configuration/setup( I thought the NuGet facilty was installed as part of the “overall” GTA tooling)?



      • Hi Herman. Thanks for the input.
        (1) While step 2 (now step 4) made reference to adding c:\googletest\googletest and c:\googletest\googletest\include directly to the Include Directories, the rest of the post was written assuming user-wide settings. I have now corrected this by specifying what needs to be done in both cases.
        (2) msdia.dll is a file that is installed as part of Visual C++. The only thing I can think of is that it was not properly installed when you installed Visual Studio.

        Hope this helps.


      • Hi usingcpp,

        thanks for your reaction and the clarifications. In the meantime I’ve installed another VS version (2013, in addition to the 2017 version I installed earlier) and contrary to the 2017 version I performed a complete installation of all “default” modules. The “msdia.dll msg” didn’t occur anymore, which also solves the problem for the 2017 version because apparently the msdia.dll is included in the full installation and is also picked up by the 2017 environment thereafter. So the full installation solved the issue for me as you already suggested.



  2. This is very helpful.

    In step 6 where it says “Near the bottom of the file you will see the following lines:
    Change these lines to:”, it doesn’t actually say what we should see or what we should change it to. What should go there?

    Also, should the test results show up in Visual Studio 2015’s Test Results and Test Runs windows? I’m not seeing them there.


    • Thanks for pointing this out, Richard. I have corrected this.
      I think the lines disappeared when I changed the theme for this blog. At least that is what I am blaming it on. 🙂

      Once you install GoogleTestAdapter, the results should show up in the Test Explorer window as shown in the post.


  3. Pingback: Writing Unit Tests | Jim's Adventures in Programming

    • I just repeated the process as outlined in the post up to step 12 of Using Google Test and everything works as indicated. The one difference with VS 15.3.3 (maybe 15.3.0 as well) is that in step 2, you must select Visual C++ ->Windows Desktop->Windows Desktop Wizard.
      Other than that, everything seems the same. You said that you could not make it build. At what step did you have the problem?
      The only references to error 455 that I could find are related to VB and VBA.


    • I have just updated the post for use with VS2017 version 15.5 or later. For version 15.3.3, you can install Test Adapter for Google Test (or Google Test Adapter) using the Tools->Extensions and Updates… menu item. Alternatively, you could update VS2017 to the latest version.


  4. Pingback: Unit Testing Framework for C/C++ – சிந்தனை சிதறல்கள்

  5. This works only because you put your production code in header file. In case you would like to test a class (which is declared in .h and defined in .cpp) it doesn’t work. There are LNK2019 problems.. Do you know how to fix it?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s