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'sgoogletest\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\
hasGoogleTestLib.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.