Search code examples
visual-studiocmakegoogletest

Using Google Test Adapter for Visual Studio with CMake


A have a CMake-based project which uses Google Test for unit testing and I am using the Visual Studio generator to create my project/solution files.

I would like to be able to run my Google Test unit tests from the Visual Studio Test Explorer so that I can keep everything within the IDE. I heard about Google Test Adapter but obviously right out of the box it does not "know" where my tests are or how to run them.

How can I set this up to properly discover my tests? Can I just throw them in a directory and have GTA look for them that way?


Solution

  • I am using the GoogleTestRunner plugin in my projects. This works pretty well, but notice that your executable needs a name, matches the regular expression "[Tt]est[s]{0,1}.exe" (e.g. MyProjectTest.exe).

    By the way, this has no relation to cmake. But of cource, using cmake is no obstacle to use this plugin :).