LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Answered

What are the common subtypes of code coverage?

Anyone knows about the common subtypes of code coverage?

Up Vote Down Vote 0 Votes
Posted 3 months ago

Answers


Some of the common subtypes of code coverage are:

  • Branch coverage – Branch coverage also called decision coverage is used to ensure that every possible branch used in a decision-making process is executed. For example, if you are incorporating a fall back for cross-browser compatibility using an If…An else conditional statement or by a Do…While statement in your code, as a part of coverage; you have to ensure that all the branches i.e. If, Else, Do, and While are tested by providing appropriate inputs to make a cross browser compatible website.

  • Function coverage – Function coverage ensures that necessary functions (especially exported functions/APIs) are tested. This should also include testing the functions with different types of input parameters as that would also test the logic used in the functions. Once all the functions in the code are tested, function coverage would be 100%.

  • Statement Coverage – This is an important code coverage methodology in which test code has to be written in a manner that every executable statement in the source code is executed at least once. This also includes corner cases or boundary cases.

  • Loop Coverage – This approach is to ensure that every loop in the source is executed at least once. There might be some loops that may execute based on results that you achieved at runtime, it is important to test such loops as well in order to make the code foolproof.

For checking the code coverage, an approach called instrumentation is used. Instrumentation can be used to monitor the performance, insert trace information, and diagnose any kind of errors in the source code. There are different kinds of instrumentation and there could be a minimal performance (and timing) overhead depending on the instrumentation approach being used.

Please let me know if this answer is helpful. Thanks!

Up Vote Down Vote 0 Votes
Posted 3 months ago