I want the c++ unit test written in google test displayed in the VS 2019 test explorer.
The tests are setup correctly and can be executed. The results are shown in the VS debug console/commandline-like window. No error messages besides the test dependent messages are shown. I want start the tests form the test explorer and want to create test play lists.
I installed the google test adapter provided by the VS Installer. I followed guidelines and the suggested troubleshooting at TestAdapterForGoogleTest.
Does another way exist to get the google test to be dispalyed in the test explorer? What are other known incompatibilities with google test and the VS test explorer?
I had the same problem as you. I'm having a main CMakeLists.txt, and another two CMakeLists.txt files in the subdirectories: one for the static library I'm testing and one for the test project itself. For making sure the tests appear in the Test Explorer I had to move
enable_testing()
from the test subdirectory into the main CMakeLists.txt.Then in the test subdirectory, I'm setting up the GoogleTest environment, and adding test the following way:
The very last line is important. Instead of
gtest_add_tests
, you can also useadd_test
. It needs different parameters but that works too when your goal is showing test cases in VS2019's Test Explorer.The reason the above solution helped:
When you add
enable_testing()
to your top-level CMakeLists.txt file, it will generate a top-level CTestTestfile.cmake file in your build directory. This is needed by the Test Explorer to roll up all the test cases generated during the build process. If you've got a certain CMake hierarchy within your code structure you should have a similar one for CTest.My top-level CTestTestfile.cmake file content:
The lower level CTestTestfile.cmake file content: