3

I'm using visual studio 2017 on Windows 10. I created a new google test project to test another project of mine. #include "gtest/gtest.h" does not give compile errors, but #include "gmock/gmock.h" does! Looking inside of the external dependencies folder I see that gtest.h is there, but not gmock.h. So when I do try including mock, the compiler gives me this error: "Cannot open included file: 'gmock/gmock.h': No such file or directory". When I go into Tools -> Extensions and Updates, I see that Test Adapter for Google Test has version: 0.10.1.7 and its release notes say it supports Google Test V1.8.0 which has google mock according to https://github.com/google/googletest/releases.

  1. Why is gmock.h not there? Do I need to update the "Test Adapter for Google Test" or Google Test itself? Is it because I may have a lower version of google test? I'm not even sure how to find the version of Google Test that I have; it doesn't say.

  2. Should I not use the Test Adapter and instead try configuring the latest release of googletest myself into visual studio 2017?

  3. what's the best way to get gmock working with my setup?

Ahmed Abdelazim
  • 133
  • 1
  • 7

1 Answers1

2

For some reason the Visual Studio 2017 comes with Google Test but not Google Mock.

This question explains how to update the standard package to a package that includes Google Mock. However that didn't work for me.

I solved it by downloading Google Test (including Google Mock) and building it myself.

After that, create a new console application project (not a Google Test project). Change the configuration to include the Google Test include directories and link with the Google Test libraries. For Google Test 1.8.1 and Debug configuration:

  • add $(GTEST_DIR)\googletest\include and $(GTEST_DIR)\googlemock\include to additional include directories;
  • add gtestd.lib, gmockd.lib and gmock_maind.lib to additional dependencies;
  • add $(GTEST_DIR)\googlemock\gtest\Debug and $(GTEST_DIR)\googlemock\Debug to additional library directories.

Here $(GTEST_DIR) is the location where you built Google Test. Replace it with the actual directory or set the environment variabele.

If you build the application, Visual Studios Test Explorer should recognize it as a Google Test application.

rveerd
  • 3,620
  • 1
  • 14
  • 30