mkdir mybuild
cd mybuild/
cmake -Dgtest_build_tests=ON -Dgmock_build_tests=ON $GTEST_REPO_DIR ..
make
make test
To add and run a new unit test in GoogleTest, follow these steps:
- Create Your Test File: Name it
file_unittest.cc
. - Update
CMakeLists.txt
: Add your test file togoogletest/CMakeLists.txt
under theif (gtest_build_samples)
section, similar to how other samples are added, e.g.,cxx_executable(sample3-inl_unittest samples gtest_main)
. - Build and Test: In your terminal, run
make
to build the project, thenmake test
to run all tests, including your new test. - Run Only Your Test: Execute your specific test by running the generated executable, for example,
googletest/sample3-unittest
.
- Always check for
CmakeLists.txt
file to enable test flag and tweak some config for it.