Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google-test: code coverage

Is it possible to get code coverage done by tests using google test framework?

like image 245
gruszczy Avatar asked Mar 01 '10 21:03

gruszczy


People also ask

How do you test code coverage?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

What is good test code coverage?

With that being said it is generally accepted that 80% coverage is a good goal to aim for. Trying to reach a higher coverage might turn out to be costly, while not necessary producing enough benefit. The first time you run your coverage tool you might find that you have a fairly low percentage of coverage.


2 Answers

Yes, I've successfully used both free (gcov) and commercial (CTC++) tools. No special steps are needed, just follow the documentation.

More details can be found in this blog http://googletesting.blogspot.dk/2014/07/measuring-coverage-at-google.html

like image 117
chalup Avatar answered Oct 22 '22 06:10

chalup


Yes, You can club your Gtest Based application with support of Gcov/lcov. refer the documentation of lcov http://ltp.sourceforge.net/coverage/lcov.php

there is one linux test project utility available which does your job very easy and is very self-interpretative.

lcov - a graphical GCOV front-end

Download from Ubuntu repo:

$ sudo apt-get install lcov
  1. Use following commands in your build directory

    $ lcov --directory ./build/ --capture --output-file ./code_coverage.info -rc lcov_branch_coverage=1
    
  2. Run the Application

  3. Generate HTML Report

    $ genhtml code_coverage.info --branch-coverage --output-directory ./code_coverage_report/
    

This will look something like - http://ltp.sourceforge.net/coverage/lcov/output/index.html

like image 19
Jinay Patel Avatar answered Oct 22 '22 06:10

Jinay Patel