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:
There are various parameters & criteria, to measure the code coverage. Below given are some of the important types:
Whether, each and every function which is declared and defined, has been called or not during the execution of the program.
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.
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.
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.
Below given are some of the tools to measure the code coverage under the test.
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.