New CLion 1.2 EAP (build 143.249.8) brings you Google Test

Anastasia Kazakova

Getting closer to the 1.2 release, today we are happy to introduce Google Test support in CLion! It’s taken quite a lot of work, and though some issues are still present we are ready to share the results with all of you and anxious to hear your feedback.

Download the build from our confluence page, or get a patch update if you’re using a previous EAP build.

Google Test support consists of three features: unit tests configuration, code generation in tests, and a test runner. We’ll talk about each one in detail, but before we start, let us share a couple of tips on how to add Google Test to your project (feel free to skip this part if you already have it added).

Start with Google Test
Since installing the pre-compiled version of Google Test is not recommended, you will probably be compiling Google Test inside your project. To start, download Google Test and include it into your project. After creating one or several directories for the tests, your project structure will look something like this:
Sample CMakeLists.txt in your test directories will look similar to this:

That’s mostly it! However, take note of several details regarding some specific platforms:

  • In case you are using Cygwin, use the GNU dialect of the C++ language for your project:
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
  • On OS X, only in case you select Google Test v1.6.0, you’ll need to add the following lines to your project’s CMakeLists.txt:
    if (APPLE)
    endif (APPLE)

Unit tests configuration
You can run Google Test as a regular executable, but to benefit from CLion’s built-in test runner you should create a special Google Test configuration. There are several ways of doing this:

  • Place the cursor on any test and run it from the context menu or by pressing Ctrl+Shift+F10 on Windows/Linux, Ctrl+Shift+R on OS X. The corresponding configuration will be created automatically, and you can rerun it later:
  • The same works for running all tests from one particular file or related to one fixture. Select a file or place a cursor inside it, or place a cursor on a fixture’s name and use context menu or Ctrl+Shift+F10 on Windows/Linux, Ctrl+Shift+R on OS X shortcut. Again, the configuration will be created and saved automatically for you:
  • Go to Run | Edit Configurations… and add a new Google Test configuration from the existing template:
    Then select a proper target, suite and test name, or set a pattern to run several tests.

While running one test, a set of several tests or a complete fixture or file, CLion will open a separate tool window. See what you can benefit from in the next section.

Test runner
Test runner window includes the following elements:

  • The progress bar shows the percentage of tests executed so far. The color also indicates whether the tests have passed successfully or not.
  • The pane with a tree view of all the tests running, including the information about test status (via icon) and test duration.
  • If you select a test in the test pane, the output pane will show the output of that particular test, including all the messages sent to the output stream, and the error messages.

The default layout of the testing results tool window is horizontal; if you prefer vertical, move the window to the right or left, and the console will be adjusted accordingly (note that currently you need to rerun the tests to get proper adjustments):

Test runner window also allows you to:

  • rerun any test in particular;
  • rerun all failed tests;
  • sort tests alphabetically or by duration;
  • jump to the source code of a particular test with F4 on Windows/Linux, Cmd+Down on OS X;
  • export test results; and
  • open previous results from the history, saved automatically.

Code generation
CLion’s code generation feature (Alt+Insert on Windows/Linux, Cmd+N on OS X) can be a lot of help in writing tests. Use it to generate test, test fixture or SetUp/TearDown Methods:
Generate Test, specify a fixture name and one of the appropriate TEST_F(), TEST_P(), TYPED_TEST(), TYPED_TEST_P() will be used by CLion automatically:

In addition, we’d like to add that if you are new to Google Test, check out the very useful FAQ at Google’s wiki. Get our sample project with Google Tests from github.

Give this EAP build a try and let us know what you think in the comments below! Please submit any possible problems to our tracker and see complete release notes.

Develop with pleasure,
The CLion Team

Comments below can no longer be edited.

33 Responses to New CLion 1.2 EAP (build 143.249.8) brings you Google Test

  1. Balázs Kocsi says:

    October 14, 2015

    Including gtest into a cmake project can be done automatically:

    It will download, build and include in your project. CMake magic 🙂

    • Anastasia Kazakova says:

      October 14, 2015

      You are right. There is actually even more ways. Like, for example, biicode –

      • Dragan Vidanovic says:

        May 1, 2018

        Why not make CLion automtically download gtest and put all necessary lines in CMakeList.txt? You can even create automatically test cpp files as well.

        • Anastasia Kazakova says:

          May 3, 2018

          CLion doesn’t include package manager as a built-in feature. And I think the best way is to use proper package manager for this, for example Hunter or Conan that support Google Test.

  2. Yury V. Zaytsev says:

    October 15, 2015

    Let’s hope that the parser is going to stop blowing up randomly on crazy Google Test macros, still used to happen quite frequently the week before last :-/ The UI looks great though!

    • Yury V. Zaytsev says:

      October 15, 2015

      Oh, re-indexing is much faster on git stash / git stash pop, that’s great news, it was really driving me crazy! I guess I was affected by the platform bug referenced in the release notes.

    • Anastasia Kazakova says:

      October 15, 2015

      Feel free to report cases if they are not already in the tracker. This will help a lot!

  3. Joshua Rosen says:

    October 15, 2015

    Is it possible to use the built-in test runner GUI while using a testing framework other than Google Test (in my case, a custom framework)? If not, are there plans to eventually support this? Admittedly, I’m not exactly sure how to generalize an API for the test runner…

  4. Nick says:

    October 15, 2015

    Its only been 10 minutes but this release is frick’n awesome, can’t wait for 1.2!

  5. Jonas says:

    February 3, 2016

    Is it possible to get the demo project for getting started with GoogleTest? Thank you.

    • Maria Baburina says:

      February 3, 2016

      Check out our project on GitHub!

    • Jonas says:

      February 3, 2016

      I’m stupid. Just saw the link.

      • Jonas says:

        February 3, 2016

        Thank you

        • Beth Kirby says:

          May 23, 2016

          I downloaded the project from github. I needed to add the subdirectories to the main CMakeLists.txt file & to fix the includes in the test file to point to the calendar directory, but then it runs.
          I have tried to get a project to run with the External target, but haven’t yet succeeded. I’ll try again with this project.

  6. Andrew Luca says:

    February 18, 2016

    Thanks for making world better! 🙂
    I also started to use Google Test within CLion, but i’m using it without having googletest added to my project. First I installed googletest on my system, just made a clean build, then I just used CMake commands

    find_package(GTEST REQUIRED)
    add_executable(BasicTests WorldTest.cpp)
    target_link_libraries(BasicTests ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
    target_link_libraries(BasicTests SFECS)

    Everything works like a charm! 🙂
    Good day folks!

  7. sircodesalot says:

    March 16, 2016

    Ohhh my god! Been waiting for GTest support forever, and now its here!

  8. Alexey Klimkin says:

    October 1, 2016

    How do I run multiple test executables together with the built-in test-runner?
    Here is an example of a build file:

    • Anastasia Kazakova says:

      October 3, 2016

      Unfortunately, CLion currently doesn’t support CTest (, so can’t provide you any solution now. CLion doesn’t detect test scripts presence so the approach from SO doesn’t work for now in CLion. Hope to have this added in future. Pls upvote and follow the updates in tracker.

  9. John Gluszak says:

    October 29, 2016

    If anyone’s using a mac, I turned this into a Ruby gem to cut down on project setup time. It takes one line in Terminal to create a project running a sample unit test.

  10. Albert says:

    November 4, 2016

    It awesome!!! Thank you!

  11. David K Lind says:

    May 15, 2017

    I’m running CLion 2017.1.1.

    Is there a way, from CMake, to automatically add projects to the Google Test list in Run/Debug Configurations?

    • Anastasia Kazakova says:

      May 16, 2017

      Yes, CLion automatically created Google Test configurations for the targets linked with gtest or gmock (2017.2). You just need to reload CMake in CLion and that’s it.

  12. Marc C says:

    May 23, 2017


    Would it be possible to point me towards to latest and greatest way to install and run gtest.
    Information out there seems to point in different direction since things have evolved since 2015.

    Thank you.

    • Anastasia Kazakova says:

      May 23, 2017

      Things haven’t changed that much and general way of getting gtest into your project is still as described. So feel free to download gtest and build it into your project as suggested in the blog post.

      • Marc A Charbonneau says:

        May 26, 2017

        Ok thank. Previous readings got me a bit confused. Thanks again for clarifying.

  13. Josiah says:

    February 6, 2018

    I am having issues setting this up:

    cmake_minimum_required(VERSION 3.9)


    add_executable(Eight_Queen_Solver_v3 main.cpp core/Node.cpp core/Node.h core/Problem.cpp core/Problem.h core/InformedSearch.cpp core/InformedSearch.h)

    # information for gtests
    set(CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -std=gnu++0x”)
    include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})

    target_link_libraries(Eight_Queen_Solver_v3 gtest gtest_main)
    target_link_libraries(Eight_Queen_Solver_v3 core exceptions)

    But I am getting:
    [100%] Linking CXX executable Eight_Queen_Solver_v3.exe
    /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgtest
    /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgtest_main
    /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lcore
    /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lexceptions
    collect2: error: ld returned 1 exit status
    make[2]: *** [CMakeFiles/Eight_Queen_Solver_v3.dir/build.make:173: Eight_Queen_Solver_v3.exe] Error 1
    make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/Eight_Queen_Solver_v3.dir/all] Error 2
    make: *** [Makefile:84: all] Error 2

    • Anastasia Kazakova says:

      February 6, 2018

      And where is the Google Test library located?

      • Josiah says:

        February 6, 2018

        Eight_Queen_Solver_v3 -> lib -> gtest
        Eight_Queen_Solver_v3 -> core -> Node.cpp

        I wish I could just upload a picture of my directory. I copied everything that they did, but still cant make tests.

      • Josiah says:

        February 6, 2018

        The post says: To start, download Google Test and include it into your project. After creating one or several directories for the tests, your project structure will look something like this

        But how do I include it? How is gtest_SOURCE_DIR initialized???? This isn’t explained.

        • Anastasia Kazakova says:

          February 6, 2018

          You have to put Google Test directory into your project directory. See the example here: In calendars_tests folder you can find both: Google Test lib and my Calendar tests.


Subscribe for updates