Loading

Code Coverage


What is Code Coverage?

Code Coverage may be defined as a metric tool, use to measure the coverage of the programming code, in terms of line of code, under the test. It is a type of "white-box testing", used to measure the quantity of code covered, during the execution of a program or code.

The chief purpose, behind code coverage, is to ensure that no line of code or area of the program, left unvisited or untouched for the testing purpose. Through code coverage, we may be able to get the answers to the following questions:

  • How many lines of code, is being executed, during the task of "test execution"?
  • How many lines of code or area of the programming code are still beyond the reach of "testing process"?
  • How many additional test cases, may be required, to increase the code coverage?
  • Redundant test cases, useless for increasing the code coverage.
Below given is the working formula for determining the code coverage.
Formula: Code Coverage = (Numbers of line of code, executed / Total numbers of line of code) * 100
Higher the coverage, thorough will be the testing, i.e. more the coverage, higher may be the quality. But, it is pertinent to mention that even after going for the 100% code coverage, the quality factor is still not guaranteed. Code Coverage infographics

How to Measure the Code Coverage?

There are various parameters & criteria, to measure the code coverage. Below given are some of the important types:

  1. Function Coverage:

    Whether, each and every function which is declared and defined, has been called or not during the execution of the program.

  2. Statement Coverage:

    The simplest form of the code coverage to check that whether, each and every statement not the lines has been brought under the execution during the running of the software program. Here, we have specifically said the statements not the lines, as a statement may be dispersed or covered in multiple lines or the line may contain more than one statement. You can go through our article on "statement coverage" here.

  3. Branch Coverage:

    Here, it is checked that if a node is able to traverse or jump to its all possible branches during the execution of the code.

  4. Condition Coverage:

    All the elements of a particular condition, i.e. boolean expression have been used and if the given expression is able to produce result in 'Yes' and 'No' form during the execution of the code .

    Sometimes, condition coverage may also be seen as the decision coverage, which is the combination of function and branch coverage and used to check that every possible entry and exit points in the programming code has been called upon or not, at least once, and if all the possible outcomes of every decision has been invoked or not during the execution.

Apart from the above mentioned important criteria, following types may also be approach for measuring the code coverage.

  • "Path Coverage".
  • Call Coverage.
  • Data flow Coverage.
  • Loop Coverage.
  • State Coverage.
  • Multiple Condition Coverage.

Code Coverage Tools

Below given are some of the tools to measure the code coverage under the test.

  1. Hansel → for Java.
  2. EMMA→Java
  3. Quilt→ Java
  4. Jcoverage→Java
  5. Clover.Net→.Net
  6. Ncover→ .Net
  7. Squish Coco→ C/C++
  8. Devel::Cover→Perl
  9. Large project→Python
  10. Pylid→Python
  11. PHP Test Coverage Tool→ PHP
  12. Cobertura → for Java.
  13. CodeCover → for Java.
  14. Coverage.py → for Python.
  15. Gretel → for Java.
  16. JaCoCo → for Java.
  17. JCov → for Java.
  18. NoUnit → for Java.
  19. PITest → for Java.
  20. Serenity BDD → for Java and Groovy .
  21. Atlassian Clover → for Java and Groovy.
  22. Bullseye Coverage → C, C++.
  23. FrogLogic Coco → C, C++, C#.
  24. Testwell CTC++ → C, C+, Java, and C#.
  25. NCover →.NET.
  26. Intel C++ Compiler 15.0 → C++.
  27. Parasoft Jtest → C, C++, Java, and .NET.
  28. SpiraTeam → Any programming language.
  29. Vector Software → C, C++.

Code Coverage vs. Test Coverage

Both code coverage and test coverage are an integral part of software testing, as they allow QA analysts to determine the quality of the application as well as how thoroughly it is tested. The former, as stated earlier, defines the code that is exercised when the application is running, while the latter refers to metrics in an overall test plan. Let us further understand the differences between these two coverage metrics:

Code Coverage Test Coverage
1. Code coverage is a white-box testing technique. 1. Test coverage is a "black box testing" technique.
2. In order to assess coverage, it needs to see the application code.. 2. It has minimal interaction with the application code.
3. It is a measure of how the code is executed during the test. 3. It is a measure of how many test cases have been executed during the test.
4. It never uses a design specification. 4. It is aligned to the Requirement Specifications.
5. Performed by developers. 5. Performed by the QA team.

You can also explore points of differences between "statement,branch and decision coverage" here.


ThinkSys Advertisement


ThinkSys Advertisement
ThinkSys Advertisement



Get New Content Update
Popular Posts
Dec 07, 2020
Dec 07, 2020
Dec 07, 2020

Advertisement:

ThinkSys Advertisement


LP

App development ad thinksys

Devops