Clion Ctest

Posted onby admin
  • Compatible with CLion. C and C Line, Region and Branch Coverage gatherer for GCC and Clang. Automatically gathers line, region and branch coverage and displays it in editor and a statistic window. It lacks some features. I widely use coverage analysis provided by CTest + CDash web view. May be this view looks.
  • CTest, a CMake-specific test runner, is supported in CLion. This means the list of tests that are run with CTest is detected, and the IDE automatically creates run/debug configurations for them.

This post explains how to run code coverage using gcov in an external or remote module of ITK. It only has some specific of ITK, so it can be useful for using gcov for other projects.

First, change the compile flags to report code coverage. I am only interested in running it for my module, if you want to run it for all your project, just append COVERAGE_FLAGS to CMAKE_CXX_FLAGS, and all your targets will compile with those flags.

Using gtest/gmock with CMake is awesome. Not so awesome is when you don’t have a pre-built gtest/gmock available to use. This article demonstrates a convenient way to add them with automated source download and have them build directly as part of your project using addsubdirectory.

In my case, I will modify the compile flags of the test driver of the module.


Coverage files .gcno will be generated in the same folder than the object files cxx.o. Check it: ls test/CMakeFiles/IsotropicWaveletsTestDriver.dir/ grep gcno

Now run your test:

I have a little bash script to run itk tests, if I want to change the test to run I just have to change the CTEST_ARGS variable, for example: export CTEST_ARGS='-R FrequencyBandPass -V'.

To run all the test of my module, I export CTEST_ARGS='-L IsotropicWavelet' and call test anywhere in the terminal. This will generate .gcda files ONLY if all the test exit succesfully (no errors, no uncaught exceptions).

Clion Ctest Integration

To visualize the data stored in those .gcda we can use lcov and genhtml to generate beatiful html reports, I am following these two posts:C++ code coverage profiling with GCC/GCOV and the post C++ Code Coverage Analysis with CMake and Jenkins.

In arch-linux, lcov is in the AUR.

You can use: lcov --directory $COVERAGE_PREFIX --zerocounters to clean the coverage data before a new run of your tests.

When the data is up-to-date, use:

This will parse all .gcda files in the directory.

Now use genhtml:

Clion Ctest

Then use your favourite browser to open the html report:

Well, it seems I have some work to do!

Clion Run Ctest

I have put these functions in a bash script

CLion 2020.3 is released!

Clion Cmake Ctest

CLion 2020.3: Core Dumps Debug and Debug as Root, CTest Support, MISRA Guideline Integration, and a Better Qt Project Experience

RunClion Ctest

by Anastasia Kazakova

CLion 2020.3 brings significant improvements to key parts of the development process – code analysis, running and debugging applications, and unit testing.

  • Run and Debug:
    • Run/Debug with Root privileges
    • Debug core dumps
    • Move the execution point while debugging to an arbitrary line of code in the editor
  • Project models
    • For Makefile: support for projects using libtool, dolt and ccache
    • For CMake: enable/disable CMake Profile
  • Unit testing: CTest support and test runner improvements for Google Test
  • Code analysis and refactorings updates, including initial support for MISRA C 2012 and MISRA C++ 2008 guidelines
  • Better Qt projects support
  • Clang completion snippets
  • An early preview for Code With Me, a new service from JetBrains for collaborative development and pair programming.