GTestSetupRemoteDownload
See https://github.com/AlexandreBrown/GTestSetup to setup GTest by downloading the GitHub repo instead of downloading it via CMake.
Setup after cloning :
Depending on how you want to run your tests there might be some setup required.
Running Tests Using CLion/An IDE (Recommended):
- No additional setup required.
- To run the all the tests inside
MyClassTest
you can use the run button at the test fixture or test name- You can also right click a folder with tests and run all the tests or you can run individual tests using the green run button
- You can also run tests from the bottom pane that opens up after runnign tests initially
- Using the IDE to run tests might provide better feedback than other alternatives (subjective)
Running Tests Using CTest:
- Create build directory from the root of
GTestSetup
folder (eg:GTestSetup/build
).
mkdir build
cd build
- Try to cmake and make to ensure your project is well setup
- In a terminal at
GTestSetup/build
location, do the following commands:cmake ..
make
- If no error occured then everything should be setup correctly.
- Run unit tests
- Run the following inside of the
GTestSetup/build
folder :make && make test
or simplymake test
if you already didmake
and no files changed since.
Known issues and workaround
Global fixes to try :
- Delete
/build
folder and recreate/populate it usingmkdir build
+cmake ..
+make
- CLion : File->Invalidate cache & restart
Cannot run tests using play button :
- Try to right click your test class from the file explorer (inside CLion) and click "Run all in YourClassTest.cpp"
- If it doesn't work try deleting the
/build
folder and recreating it and repopulating it using steps describe in Global fixes to try - If it doesn't work try running your tests using
make test
from/build
folder
Fatal error: gtest/gtest.h: No such file or directory #include <gtest/gtest.h> :
- Change the include from #include <gtest/gtest.h> to #include "gtest/gtest.h"
- If the error still occurs try deleting
/build
and recreating/populating it using steps describe in Global fixes to try
Cannot find "gtest/gtest.h" / Don't have play button to run test inside my test class :
- Try deleting
/build
and recreating/populating it using steps describe in Global fixes to try
Code change is not reflected (test should fail but passes etc) :
- Try re-running the test, maybe it was ran with outdated code or try
make && make test
from/build
Could not build /cmake-build-debug does not exist :
- Try File->Invalidate cache & restart