Skip to content

Instantly share code, notes, and snippets.

@abhishekmishragithub
Created March 14, 2024 12:33
Show Gist options
  • Save abhishekmishragithub/89d4e4080666e3c45fcc5a81f90d0416 to your computer and use it in GitHub Desktop.
Save abhishekmishragithub/89d4e4080666e3c45fcc5a81f90d0416 to your computer and use it in GitHub Desktop.
googletest setup <> Codium AI

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:

  1. Create Your Test File: Name it file_unittest.cc.
  2. Update CMakeLists.txt: Add your test file to googletest/CMakeLists.txt under the if (gtest_build_samples) section, similar to how other samples are added, e.g., cxx_executable(sample3-inl_unittest samples gtest_main).
  3. Build and Test: In your terminal, run make to build the project, then make test to run all tests, including your new test.
  4. Run Only Your Test: Execute your specific test by running the generated executable, for example, googletest/sample3-unittest.

image


Thumb Rule

  • Always check for CmakeLists.txt file to enable test flag and tweak some config for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment