Coco

With Coco, you can measure and analyze the code coverage of tests. You can set up a project for code coverage and display the coverage in Qt Creator.

To use the plugin, you must download and install Coco version 6.0 or later.

Note: Enable the Coco plugin to use it.

Set Coco installation directory

Go to Preferences > Coco to set the Coco installation directory. Usually, you don't need to change the default value.

Create a build configuration for Coco

To create a build configuration for Qt Creator projects that you build with qmake or CMake:

  1. Go to Projects > Build & Run > Build > Build Settings.
  2. Select an existing build configuration, such as Debug, and then select Clone to clone it with a new name, such as DebugCoverage.
  3. Configure the clone for use with Coco.

Do not switch back and forth between coverage and normal builds using the same build configuration.

Build Settings > Build Steps > Coco code coverage shows whether code coverage is on or off for the build configuration. Select Enable Coverage or Disable Coverage to turn on or off code coverage.

{Setting code coverage from a build step}

Set code coverage for a project

To specify code coverage settings for a project, go to Projects > Project Settings > Coco Code Coverage.

{Coco Code Coverage settings}

SettingPurpose
Enable code coverage for build configuration <name>Turns on and off code coverage for a build configuration.
CoverageScanner OptionsCode coverage options (optional).
Exclude FileExcludes a file from instrumentation.
Exclude DirectoryExcludes a directory from instrumentation.
OverrideEnter commands to add them to the end of the settings file. Use this option when the usual configuration flags are not enough.
Changed Build SettingsLists the changed project build settings.
RevertReloads the coverage settings from the current settings file.
Save and Save & Re-configureWrite the settings to the settings file and reconfigure the project if necessary.

If code coverage is on, the plugin generates a settings file that the build tool reads first. It changes the build process to use Coco compiler wrappers instead of the original compiler. The settings file is always located in the root directory of the project sources. It also has the coverage flags and possible overrides. Check it into version control to preserve the settings.

qmake projects

For qmake projects, the settings file is the cocoplugin.prf feature file.

For a command-line build, run qmake with the additional options:

CONFIG+=cocoplugin COCOPATH=<Coco directory>

Also, set the environment variable QMAKEFEATURES to the directory where cocoplugin.prf is located.

CMake projects

For CMake projects, the settings file is the cocoplugin.cmake CMake cache preload script. Also, the compiler files cocoplugin-gcc.cmake, cocoplugin-clang.cmake, and cocoplugin-visualstudio.cmake are created in the same directory. They are needed for a command-line build.

To build the project from the command line (when compiling with GCC), enter:

cmake <other options> -C <project dir>/cocoplugin-gcc.cmake

The file cocoplugin-gcc.cmake includes cocoplugin.cmake.

If you use some other compiler than GCC, Clang, or MSVC, modify one of the compiler files for that compiler.

See also Configure projects for building, Enable and disable plugins, View code coverage reports from Coco, Font & Colors, and Analyzing Code.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.