I'm new to using gtest (actually, C++ in general) I'm making an application where I need to have unit tests (using CLion IDE, in case if that matters).
The steps I followed:
- Download gtest from GitHub.
- Extracted the zip file into a new
libdirectory in my project. Modify CMakeLists.txt
cmake_minimum_required(VERSION 3.13) project(my_project) set(CMAKE_CXX_STANDARD 14) add_subdirectory(lib/gtest) # I renamed googletest-master folder to gtest, so that should be fine. include_directories(lib/gtest/googletest/include) include_directories(lib/gtest/googlemock/include) add_executable(my_project main.cpp blablabla1.h blablabla1.cpp blabla2.h blabla2.cpp etc...) target_link_libraries(my_project gtest gtest_main)Created a new directory called
Testsand added a cpp file in it with the following code:#include "gtest/gtest.h" #include "gmock/gmock.h" TEST(TrivialTest, Negative) { ASSERT_EQ(0, 1); }I'm stuck here, how should I run this test? If I put the following code in
mainfunction, then tests will start every time a normal run to the program is made. I want to somehow separate the normal program running, from the unit tests running.#include "gtest/gtest.h" #include "gmock/gmock.h" int main() { testing::InitGoogleTest(); return RUN_ALL_TESTS(); }