设置谷歌模拟 1.6

Setting Up Google Mock 1.6

本文关键字:模拟 谷歌 设置      更新时间:2023-10-16

我正在尝试遵循测试驱动开发的现代C++编程,为此,本书指导读者安装 谷歌模拟 1.6。尝试这样做,我从这里下载了源代码。然后根据这本书我做的:mkdir build cd build cmake .. make

myComputer:build me$ cmake ..
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- The C compiler identification is AppleClang 8.0.0.8000042
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:56 (add_subdirectory):
add_subdirectory given source "../gtest" which is not an existing
directory.

CMake Error at CMakeLists.txt:61 (config_compiler_and_linker):
Unknown CMake command "config_compiler_and_linker".

-- Configuring incomplete, errors occurred!
See also "/Users/me/Downloads/googlemock-release-1.6.0 3/build/CMakeFiles/CMakeOutput.log".

这。。/gtest 目录确实丢失了。因为这些是目录:

CHANGES     COPYING     build       include     scripts
CMakeLists.txt  Makefile.am build-aux   make        src
CONTRIBUTORS    README      configure.ac    msvc        test

更令人困惑的是这些说明:

You will also need to build Google Test, which is nested within Google Mock.
cd $GMOCK_HOME/gtest
mkdir mybuild
cd mybuild
cmake ..
make

我查看了自述文件,似乎没有任何有助于解决此问题的内容。任何帮助/指导都会超级棒!

正如你在这里看到的,Google Mock已经被吸收到GoogleTest项目中。

有多种方法可以安装 GoogleTest,如 GoogleTest 自述文件中所述。由于您似乎正在使用CMake,因此建议您按照以下步骤操作

合并到现有的CMake项目中

你也可以把所有应该放到CMakeLists.txt放到CMakeLists.GTest中,然后只把include(CmakeLists.GTest)放到CMakeLists.txt中。

如果您想确定应该合并的GoogleTest的固定版本,则可以在 CMakeLists.txt.in 中使用GIT_TAG例如release-1.8.0´ instead ofmaster'。

将GoogleTest合并到您的项目中后,您可以通过创建例如FooTest为类Foo添加gtest.cpp其中包括gtest/gtest.hFoo.h。因此,您还必须将add_executable(FooTarget FooTest.cpp)target_link_libraries(FooTarget gtest)放入相应的CMakeLists.txt中。

您还可以在这些幻灯片上找到对此的简短描述,以及如何将GoogleTests集成到ctest中)。

你需要在 gmock dir 中有一个 gtest。 我最初遇到了与您相同的错误,然后从 https://github.com/google/googletest 中获取了 gtest 版本 1.6 并将其放置在 gmock 根目录中并成功构建了它。