11

I have 3 questions :

  • What is CodeCoverage ?
  • What is it good for ?
  • What tools are used for analyzing Code Coverage ?
joe
  • 34,529
  • 29
  • 100
  • 137
n00ki3
  • 14,529
  • 18
  • 56
  • 65
  • 1
    Does this answer your question? [What is code coverage and how do YOU measure it?](https://stackoverflow.com/questions/195008/what-is-code-coverage-and-how-do-you-measure-it) – Inigo Aug 05 '22 at 15:13

9 Answers9

13

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

Community
  • 1
  • 1
joe
  • 34,529
  • 29
  • 100
  • 137
4

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

rahul
  • 184,426
  • 49
  • 232
  • 263
3

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.

CsTamas
  • 4,103
  • 5
  • 31
  • 34
  • Code Coverage doesn't directly mean that you have tested your code well. If you do very good tests and have them of a high test value then you will have good code coverage – AutomatedTester Jul 21 '09 at 11:28
  • Agree, however to get high coverage value, one has to create tests for the many error cases usually the code contains. This will imply "good" tests – CsTamas Jul 22 '09 at 08:06
2

Code coverage is a measure used in software testing. It describes the degree to which the source code of a program has been tested.

http://en.wikipedia.org/wiki/Code_coverage

The wikipedia definition is pretty good, but in my own words code coverage tells you how much automated testing you have accounted for. 100% would mean that ever single line of code in your application is being covered by a unit test.

NCover is an application for .NET

Bob
  • 97,670
  • 29
  • 122
  • 130
1

The term refers to how well your program is covered by your tests. See the following wikipedia article for more info:

http://en.wikipedia.org/wiki/Code_coverage

Anon
  • 11,870
  • 3
  • 23
  • 19
0

The other answers already cover what Code Coverage is. The think I'd like to stress is that you need to be careful not to treat high coverage as implicitly meaning you've tested all scenarios. It doesn't necessarily say how well you've tested the code or the quality of your tests, just that you've hit a certain percentage of code as part of the tests running.

High Code Coverage does not necessarily mean High Test Quality, but High Test Quality does mean High Code Coverage

In practice, I usually aim for 90-95% code coverage which is often achievable. The last few % are often too expensive to be worth trying to hit.

AdaTheDev
  • 142,592
  • 28
  • 206
  • 200
0

There are many ways to develop applications. One of those is "Extreme Programming" or "Test Driven Design (TDD)". It states that all code should be tested. Code Coverage is a means of measuring how much is tested.

I'd like to make a small remark about this: I don't think all code should be tested, nor that one should set a specific percentage of code coverage. Neither do I think that code shouldn't be tested with Unit Tests (code testing code). I do think one should decide what makes sense to test. Due to this reason I generally don't use code coverage.

One thing that some tools provide, is highlight the parts that are tested. This way you might run into some code that isn't tested but actually should be, which is the only thing I use it for.

Guillaume Hanique
  • 405
  • 1
  • 3
  • 8
0

Good answers.

My two cents is that there is no method of testing that catches all errors, but less testing will never catch more errors, so any testing is good. To my mind, coverage testing is not to show what code has been exercised, but to show what code has not been exercised, because that is where bugs love to lurk.

If you combine it with single-stepping, it is a very good way to review code and catch bugs. Here's an example.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
0

Another useful tool for ensuring code quality(which encompasses code coverage) that I recently used is Sonar. Here is the link http://www.sonarqube.org/

user_19
  • 581
  • 1
  • 7
  • 13