Early Access Program News

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

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