0

I'm unit testing a Visual Studio project which has already been fully developed by the client. It came to us set up with Google test; it has many tests and we're adding more. I want to use Google Mock, which I know is part of Google Test, but I don't know how to get it to build correctly. Simply adding #include "gmock/gmock.h" doesn't work, so it's not simply actually included with gtest.

Currently, the project has a dependencies folder with a vendor_google_test_release folder, which as two subfolders: (the snippets are from the vsproj file)

  • vendor_google_test_release\h has what appears to be the contents of the GTest repo's googletest\include folder. The folder is included in the add'l include directories:
<AdditionalIncludeDirectories> ... $(ProjectDir)\..\..\dependencies\vendor_google_test_release\h\; ... </AdditionalIncludeDirectories>
  • vendor_google_test_release\lib\ has GoogleTestLib.lib && GoogleTestLib.pdb, which I think they built themselves. The lib file is included in the project:
 <Link>
  <SubSystem>Console</SubSystem>
  <GenerateDebugInformation>true</GenerateDebugInformation>
  <AdditionalLibraryDirectories>$(ProjectDir)..\..\dependencies\vendor_google_test_release\lib;$(ProjectDir)..\..\dependencies\vendor_google_mock_release\lib</AdditionalLibraryDirectories>
  <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);GoogleTestLib.lib;WS2_32.lib</AdditionalDependencies>
</Link>

I've added a similar vendor_google_mock_release folder with a similar h folder (containing the contents of googlemock\include) and I've added that folder to the "additional include" folders which is where the gtest folders are included in the project.

When I add #include "gmock/gmock.h" to my code, I get a zillion errors coming from the gmock files.

I imagine what I need to do is build the google mock library, but I don't know how to do that. I'm pretty new to C++ and VS. I've followed a tutorial to build Google Test in a static library project, and added Google Mock to that as well, but it's not finding files it's looking for.

This is from the vsproj file of the attempted mock/test project:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
    <IncludePath>C:\Users\jtuzman\source\googletest-release-1.10.0\googletest\include;C:\Users\jtuzman\source\googletest-release-1.10.0\googlemock\include;$(IncludePath)</IncludePath>
  </PropertyGroup>
...
...
...
  <ItemGroup>
    <ClCompile Include="..\..\..\googletest-release-1.10.0\googlemock\src\gmock-all.cc" />
    <ClCompile Include="..\..\..\googletest-release-1.10.0\googlemock\src\gmock-cardinalities.cc" />
    <ClCompile Include="..\..\..\googletest-release-1.10.0\googlemock\src\gmock-internal-utils.cc" />
    <ClCompile Include="..\..\..\googletest-release-1.10.0\googlemock\src\gmock-matchers.cc" />
    <ClCompile Include="..\..\..\googletest-release-1.10.0\googlemock\src\gmock-spec-builders.cc" />
    <ClCompile Include="..\..\..\googletest-release-1.10.0\googlemock\src\gmock.cc" />
    <ClCompile Include="..\..\..\googletest-release-1.10.0\googlemock\src\gmock_main.cc" />
  </ItemGroup>

It's probably a relatively simple answer, I imagine. Thanks for help.

Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
  • Can you just use NuGet? Or is this an offline project? If you are developing on Windows, the Microsoft/Visual Studio way is to either use CMake or Visual Studio + NuGet to import C++ packages to do some of the setup for you. – CinchBlue Jan 26 '21 at 18:13
  • A little late, but maybe [this will help](https://stackoverflow.com/a/60486111/2118271) – Chris Olsen Feb 19 '21 at 01:17

0 Answers0