What is Code Coverage, and its significance?

The code coverage is the measurement of how much the product code has been exercised with all unit/functional/system tests.

A typical code coverage tool would produce metrics like how many or % of Java classes covered, methods covered, loops and instructions covered.

The significance of code coverage is to help in identifying the gaps in testing and also to assess the test coverage. Also, 100% code coverage should not be viewed as a high quality of the product. Instead, the results can trigger some more testing or optimization of the code.

Many times, code coverage is done after fully tested the product to see if any dead code or to find the missed testing coverage. Most of the times, the code coverage can be taken at the class level but at least method level is important. Usually, the QE team will report code coverage reports on regular basis.

The QA engineer should co-ordinate with all relevant test teams in carrying out such effort. The major tasks include the understanding of the tool and automation of the enabling the tool with the installed product, gathering the results, merging of results from different runs and publishing of the collective report. The report will be distributed to the stakeholders by a Java package name or by a module. Each module-level QE engineer can see if the results are appropriately covered or not and add the tests if required to cover all the classes and methods in that module. The feedback should be taken into the developer team to add unit tests or remove the dead or unused code for the product. Usually above 40-50% code coverage is considered as high coverage.

Why not 100% coverage target? It is all about human resources invested for testing of the product, and thereby 100% means that enormous test engineering resources requirement and practically is not feasible. Achieving higher code coverage can be aimed for any product as part of the quality testing of the product.

Some of the free and open source code coverage tools are

  • JaCoCo (nowadays more popular and originally developed from Emma)
  • JCov
  • Emma
  • Cobertura
  • Clover
  • PIT

Author: Jagadesh Babu Munta

Jagadesh Babu Munta is working as a Consulting Member of Technical Staff with Oracle America Inc. He has been with Oracle and Sun Microsystems together for over 16 years (since June 2000) in USA. Jagadesh has overall 20+ years of Software development and quality/testing experience. Jagadesh's experience has been filled recently with Cloud PaaS services, Multi-Tenancy, Security and Penetration testing. In the past, he extensively worked on Java EE servers like SailFin/GlassFish/Sun Java System/iPlanet/Netscape Application Servers. Jagadesh has gained extensive expertise in software automation, designing frameworks, writing tools, scripts, creating tests, writing specs/plans, etc. Jagadesh is interested in developing and testing complex software useful to up-level the humanity. Jagadesh Munta holds M.S. in Software Engineering from San Jose State University, California, USA; B.Tech. in Computer Science and Engineering from J.N.T.U., Hyderabad, India; Special Diploma in Electronics with Specialization in Computer Engineering, G.I.O.E, Secunderabad, India. Jagadesh Munta was born in Nellore, AP., India and lives with family in Fremont, California, USA.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s