• Software Testing Dictionary
  • Home

Software Testing - Code Coverage



Software Testing is a part of the software development life cycle (SDLC). It has a great contribution on assuring the quality of the software. Testing is subdivided into various types of testing like unit, system, integration, and acceptance testing which increases the code and test coverages.

What is Code Coverage?

The code coverage refers to the white box testing methodology done to measure the point to which the code on which the software is built has been tested. This helps in delivering a quality software and quantifies how much it has been verified.

Not only the testers, the developers are equally responsible for delivering quality software to the customers. By referring to the quality, every aspect of a software consisting of performance, maintainability, reliability, usability, security etc are considered. The code coverage is determined by the below formula −

Code Coverage = (count of lines executed)/
   (count of lines written for the complete software)* 100

Code Coverage Criteria

There are multiple code coverage criteria. They are listed below −

Coverage of Blocks or Statements

It determines the count of the statements or blocks executed triumphantly from the complete code of the software. The coverage of blocks or statements can be measured using the below formula −

Statement Coverage = (count of statements executed)/
   (count of total statements)* 100

Coverage of Branch or Decision

It determines the count of the decision or branch structures executed triumphantly from the complete code of the software. The coverage of branch or decision can be measured using the below formula −

Branch Coverage = (count of decision or branch results obtained)/
   (count of total decision or branch results in software code)* 100

Coverage of Function

It determines the count of the functions that are invoked and executed at least one time from the complete code of the software. The coverage of function can be measured using the below formula −

Function Coverage = (count of functions invoked)/(count of total functions)* 100

Coverage of Conditions

It determines the count of the boolean criteria executed in the conditional statements. The coverage of conditions can be measured using the below formula −

Condition Coverage = (count of operands executed)/(count of total operands)* 100

Advantages of Code Coverage

The advantages of code coverage are listed below −

  • The code coverage is done to ensure that the product delivered has the best quality, and performance.
  • The code coverage is helpful in measuring the extent to which the code has been tested and executed.
  • The code coverage helps to maintain the developed software code.
  • The code coverage assists in code refactoring by identifying the dead, useless, bad code etc.
  • The code coverage guides in addition to new test cases to increase the code coverage.
  • The code coverage aids in creating more effective test cases.
  • The code coverage detects defects that remain undetected.

Disadvantages of Code Coverage

The disadvantages of code coverage are listed below −

  • The code coverage occasionally fails to cover every line of code for the software.
  • The code coverage does not confirm that all the features and functionalities of the software have been verified.
  • For some scenarios, more combinations of inputs or data are required to cover test cases.
  • The developers need to be well versed with unit test cases creation to touch every scenario of software code.

Why is Code Coverage Done?

A code coverage is normally done by developers at the time of unit testing. Since the developers themselves create the tests for the code they have developed, they can measure it in a better way. They take the decision if more tests need to be added at the unit testing levels.

As more and more functionalities are added to the software, the unit tests need to be revisited, updated, and added. At the same time, however big the product has been developed, the standards have to be followed. The code coverage keeps a check on the quality of code incorporated in the complete development process.

A good measurement from the code coverage metrics signifies lower probability of undetected errors. A threshold code coverage value is set which determines if the software being shipped is fit to be deployed in the production environment.

Difference Between Code Coverage and Test Coverage

The difference between code coverage and test coverage are listed below −

Test coverage is performed with the sole intent of validating if the code developed is working as it is supposed to do. But code coverage is performed to quantify the total number of lines of code executed successfully while testing is performed.

Test coverage is mainly used for test driven development approaches.

Test coverage is adopted at the initial phases of the SDLC, where the focus is to check if the basic features have been implemented correctly. However, as we progress to the later stages of SDLC, and the complexity enhances, code coverage is normally adopted to verify if every nook, and corners of the code have been tested.

The choice of code or test converge varies from project to project based on requirements and strategy adopted for testing. However, a balanced approach of using both test coverage and code coverage metrics as per project needs help to get the optimal benefits from the both.

Different Code Coverage Tools

The different code coverage tools are listed below −

Sr.No Tool Name & Description
1

Cobertura

It's a code coverage tool that's free to use. It analyses which lines of code are executed and which are not when the test suite runs and estimates test coverage by instrumenting a code base.

2

Clover

Clover also cuts down on testing time by only executing tests that cover the application code that has changed since the last build.

3

DevPartner

Developers can use DevPartner to check Java code for Code Quality and Complexity.

4

Emma

EMMA provides coverage at the class, method, line, and base block levels, as well as at the aggregated source file, class, and method levels.

5

Kalistick

Kalistick is a third-party application that examines codes from several angles.

6

CoView and CoAnt

Coding Software is a code coverage tool that may be used for metrics, mock object creation, code testability, and path and branch coverage, among other things.

7

Bullseye for C++

BulseyeCoverage is a C++ and C code coverage tool.

8

Sonar

Sonar is an open-source code coverage tool that aids in code quality management

Conclusion

This concludes our comprehensive take on the tutorial on Software Testing Code Coverage. We’ve started with describing what is code coverage in software testing, what are code coverage criterias in software testing, what are the advantages, and disadvantages of code coverage in software testing, why code coverage is done, what are the differences between code coverage and test coverage, and what are the different code coverage tools.

This equips you with in-depth knowledge of Software Testing Code Coverage. It is wise to keep practicing what you’ve learned and exploring others relevant to Software Testing to deepen your understanding and expand your horizons.

Advertisements