Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Code Coverage?

I have 3 questions :

  • What is CodeCoverage ?
  • What is it good for ?
  • What tools are used for analyzing Code Coverage ?
like image 979
n00ki3 Avatar asked Jul 21 '09 11:07

n00ki3


3 Answers

You can get very good information from SO WEB SITE

Free code coverage tools

What is Code Coverage and how do YOU measure it?

Code Coverage is a measurement of how many lines/blocks/arcs of your code are executed while the automated tests are running.CC is collected by using a specialized tool to instrument the binaries to add tracing calls and run a full set of automated tests against the instrumented product. A good CC tools will give you not only the percentage of the code that is executed, but also will allow you to drill into the data and see exactly which lines of code were executed during particular test.

Code coverage algorithms were first created to address the problem of assessing a source code by looking directly at the source code. Code coverage belongs to the structural testing category because of the assertions made on the internal parts of the program and not on system outputs. Therefore code coverage aims at finding parts of the code that are not worth testing.

http://www.stickyminds.com/sitewide.asp?Function=edetail&ObjectType=ART&ObjectId=7580 alt text http://www.codecoveragetools.com/images/stories/software_lifecycle.jpg

Its Good for

  1. Functional coverage aiming at finding how many functions or procedures were executed.

  2. Statement or line coverage which identifies the number of lines in the source code has been executed.

  3. Condition coverage or decision coverage answers the question about the number of loop conditions were executed in the program.

  4. Path coverage which focuses on finding all possible paths from a given starting point in the code has been executed.

  5. Entry and exit coverage which finds how many functions (C/C++, Java) or procedures (Pascal) were executing from the beginning to the end.

TOOLS

http://www.codecoveragetools.com/

http://java-source.net/open-source/code-coverage

http://www.codecoveragetools.com/index.php/coverage-process/code-coverage-tools-java.html

http://open-tube.com/10-code-coverage-tools-c-c/

http://csharp-source.net/open-source/code-coverage

http://www.kdedevelopers.org/node/3190

like image 123
joe Avatar answered Sep 30 '22 19:09

joe


From wikipedia article

Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested. It is a form of testing that inspects the code directly and is therefore a form of white box testing1. Currently, the use of code coverage is extended to the field of digital hardware, the contemporary design methodology of which relies on Hardware description languages (HDLs).

Advocating the use of code coverage

A code coverage tool simply keeps track of which parts of your code get executed and which parts do not.

Usually, the results are granular down to the level of each line of code. So in a typical situation, you launch your application with a code coverage tool configured to monitor it. When you exit the application, the tool will produce a code coverage report which shows which lines of code were executed and which ones were not. If you count the total number of lines which were executed and divide by the total number of lines which could have been executed, you get a percentage. If you believe in code coverage, the higher the percentage, the better. In practice, reaching 100% is extremely rare.

The use of a code coverage tool is usually combined with the use of some kind of automated test suite. Without automated testing, a code coverage tool merely tells you which features a human user remembered to use. Such a tool is far more useful when it is measuring how complete your test suite is with respect to the code you have written.

Related articles

The Future of Code-Coverage Tools

The effectiveness of code coverage tools in software testing

Tools

Open Source Code Coverage Tools in Java

like image 41
rahul Avatar answered Sep 30 '22 19:09

rahul


Code coverage is a metric, showing how "well" the source code is tested. There are several types of code coverage: line coverage, function coverage, branch coverage.

In order to measure the coverage, you shall run the application either manually or by automated test.

Tools can be divided in two categories: - the ones that run the compiled code in a modified environment (like the debugger), counting the required points (functions, lines, etc.); - the ones that require special compilation - in this case the resulting binary already contains the code which actually does the counting.

There are several tools for measuring and visualizing the result, they depend from platform, from source code's language.

Please read article on Wikipedia

To provide you tools, please define for which OS and language do you use.

like image 21
CsTamas Avatar answered Sep 30 '22 18:09

CsTamas