I am trying to integrate Ctest and googletest in my project. I included googletest in my project as described in https://crascit.com/2015/07/25/cmake-gtest/.
I created a new test folder with a CoreTest.cpp and a CMakeLists.txt. The CMakeLists contains:
ADD_EXECUTABLE(CoreTest CoreTest.cpp)
TARGET_LINK_LIBRARIES(CoreTest corelib gtest gmock)
ADD_TEST(NAME CoreTest COMMAND CoreTest)
CoreTest.cpp contains:
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
//return RUN_ALL_TESTS();
return 0;
}
This fails:
1>------ Rebuild All started: Project: RUN_TESTS, Configuration: Debug x64 ------
1> Test project
1> Start 1: CoreTest
1> 1/1 Test #1: CoreTest .....................***Failed 1.52 sec
1>
1> 0% tests passed, 1 tests failed out of 1
However if I comment the InitGoogleTest line then the test succeeds.
Any idea on what could be the problem here ?
Many thanks !
Thanks axalis! I tried to run from the command line and realized that the googletest dlls were not in my path, which was the problem.
I added multiple tests but I can only see the ctest output in MSVC:
1>------ Rebuild All started: Project: RUN_TESTS, Configuration: Debug x64 ------
1> Test project
1> Start 1: CoreTest
1> 1/1 Test #1: CoreTest ..................... Passed 0.03 sec
1>
1> 100% tests passed, 0 tests failed out of 1
Is there a way to see the googletest output like what I get from the console ?:
>CoreTest.exe
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from MathTest
[ RUN ] MathTest.TwoPlusTwoEqualsFour
[ OK ] MathTest.TwoPlusTwoEqualsFour (0 ms)
[ RUN ] MathTest.TwoPlusFourEqualsSix
[ OK ] MathTest.TwoPlusFourEqualsSix (0 ms)
[----------] 2 tests from MathTest (1 ms total)
[----------] Global test environment tear-down
[==========] 2 tests from 1 test case ran. (4 ms total)
[ PASSED ] 2 tests.
CoreTest
command directly from the command line? (there might be a segfault, or other clues why the test fails - CMake test run only shows the fail/success state but not the actual errors ... or you can normally find the reports in the "Testing" folder) – axalisRUN_TESTS
target is generated by CMake and don't know if there is a way to control the options used in executing ctest command throughRUN_TESTS
. When you do runctest
on the command line, you can add -V to get all the output. Now my question: I have the same original problem you have. How did you fix it? Did you pass the gtest DLL path to CTest, say through a CMake variable? The only way I could getRUN_TESTS
to work is if I copied the gtest DLLs to the install directory where all my app's DLLs reside. Thanks for responding – NameRakes