gtest的helloWorld

参考官网:https://google.github.io/googletest/quickstart-cmake.html

【流程】

1)CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
project(my_project)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

enable_testing()

find_package(GTest REQUIRED)
add_executable(
  hello_test
  hello_test.cc
)
target_link_libraries(
  hello_test
  GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(hello_test)

 

增加find_package

2)编译运行

cmake -S . -B build
cmake --build build
cd build && ctest

3)代码量

总共7w行代码,googleTest目录3w行,googlemock目录2.3w行

posted @ 2022-09-11 18:21  stupidstan2019  阅读(69)  评论(0编辑  收藏  举报