0% found this document useful (0 votes)
361 views5 pages

Code Coverage PDF

This document explains how to set up OpenCppCoverage, a tool for measuring code coverage of unit tests. It describes downloading and installing OpenCppCoverage, modifying the main function to only contain test calls, and setting debug options in Visual Studio. It then explains how to generate a code coverage report by running OpenCppCoverage from the command line, which will produce an HTML report with the percentage of executed lines for the project and individual files. The goal is to achieve at least 99% coverage for all modules except the UI.

Uploaded by

Alex Ps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
361 views5 pages

Code Coverage PDF

This document explains how to set up OpenCppCoverage, a tool for measuring code coverage of unit tests. It describes downloading and installing OpenCppCoverage, modifying the main function to only contain test calls, and setting debug options in Visual Studio. It then explains how to generate a code coverage report by running OpenCppCoverage from the command line, which will produce an HTML report with the percentage of executed lines for the project and individual files. The goal is to achieve at least 99% coverage for all modules except the UI.

Uploaded by

Alex Ps
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SETTING UP OPENCPPCOVERAGE

This document has been translated and adapted from:


http://www.cs.ubbcluj.ro/~istvanc/oop/lab/Codecoverage.pdf.

OpenCppCoverage is a tool for verifying unit testing coverage, but it can also be used to count
the executed lines in a program for debugging purposes.

1. Download and install OpenCppCoverage from: https://opencppcoverage.codeplex.com/.


When installing, do not modify the default options (tool path will be added to the PATH
environment variable).

2. Modify your main() function to only contain the test function calls (comment everything
else).

int main()
{
Tests::testAll();

/*Repository repo{};
Controller ctrl{ repo };
UI ui{ ctrl };
ui.run();*/

return 0;
}

3. In Visual Studio, go to Project Properties (right-click on the Project -> Properties) -> Linker
-> Debugging -> in Generate Debug Info, select Optimize for debugging (/DEBUG).
HOW TO GENERATE CODE COVERAGE DOCUMENT
1. Open a command prompt having the project directory as current directory. In Windows,
you can type cmd in the File Explorer Address Bar, before the path:
2. When the command prompt opens, run the following command:

OpenCppCoverage --sources <folder_containing_source_files> -- <path_towards_executable>

3. The executable will be run and then the OpenCppCoverage tool generates, in the current
directory, an html report regarding the percentages of executed lines. This report will be called:
CoverageReport-<year>-<month>-<day>-<hour>h<minute>m<second>s (e.g.: CoverageReport-
2017-04-01-00h37m42s). A new such report will be generated each time the tool is run.

4. If you open the index.html file, you will see the coverage for the entire project:

5. When clicking on the link, you can see the coverage for each of the individual files in your project:
6. Make sure you have at least 99% coverage for all your modules, except the UI. We need at least
99% coverage in our (rather simple) applications, as less than 99% would mean that a certain line
of code has never been run (e.g. a one-line function, a special case in a function). In real
applications, code coverage less than 99% is accepted.

You might also like