Minimum Acceptable Code Coverage (2024)

This paper discusses how to decide what percentage of code coverage you need.

By Steve Cornett.Copyright © Bullseye Testing Technology 2006.All rights reserved.Redistribution in whole or in part is prohibited withoutpermission.

Summary

Code coverage of 70-80% is a reasonable goal for system test of mostprojects with most coverage metrics.Use a higher goal for projects specifically organized for high testability orthat have high failure costs.Minimum code coverage for unit testing can be 10-20% higher than for system testing.

Introduction

Empirical studies of real projects found that increasing code coverage above 70-80% is time consuming and therefore leads to a relatively slow bug detection rate.Your goal should depend on the risk assessment and economics of the project.Consider the following factors.

  • Cost of failure.Raise your goal forsafety-critical systems or where the cost of a failure is high,such as products for the medical or automotive industries,or widely deployed products.
  • Resources.Lower your goal if testers are spread thin or inadequately trained.If your testers are unfamiliar with the application,they may not recognize a failure even if they cover the associated code.
  • Testable design.Raise your goal if your system has special provisions for testingsuch as a method for directly accessing internal functionality, bypassing the user interface.
  • Development cycle status.Lower your goal if you are maintaining a legacy system where the original design engineers are no longer available.

Many projects set no particular minimum percentage required code coverage.Instead they use code coverage analysis only to save time.Measuring code coverage can quickly find those areas overlooked during test planning.

Defer choosing a code coverage goal until you have some measurements in hand.Before measurements are available,testers often overestimate their code coverage by 20-30%.

Full Coverage Generally Impractical

Although 100% code coverage may appear like a best possible effort,even 100% code coverage is estimated to only expose about half the faults in a system.Low code coverage indicates inadequate testing, but high code coverage guarantees nothing.

In a large system, achieving 100% code coverage is generally not cost effective.Some reasons are listed below.

  • Some test cases are expensive to reproduce but are highly improbable.The cost to benefit ratio does not justify repeating these tests simply torecord the code coverage.
  • Checks may exist for unexpected error conditions.Layers of code might obscure whether errors in low-level code propagate up to higher level code.An engineer might decide that handling all errors creates a more robust solutionthan tracing the possible errors.
  • Unreachable code in the current version might become reachable in a future version.An engineer might address uncertainty about future development by investing alittle more effort to add some capability that is not currently needed.
  • Code shared among several projects is only partially utilized by the project under test.

Generally, the tester should stop increasing code coverage when the tests become contrived.When you focus more and more on making the coverage numbers better,your motivation shifts away from finding bugs.

Unit, Integration and System Testing

You can attain higher code coverage during unit testing than in integrationtesting or system testing.During unit testing, the tester has more facilities available,such as a debugger to manipulate data and conditional compilation to simulate error conditions.

Likewise, higher code coverage is possible during integration testing than in system testing.During integration testing, the test harness often provides more precise controland capability than the system user interface.

Therefore it makes sense to set progressively lower goals for unit testing,integration testing, and system testing.For example, 90% during unit testing, 80% during integration testing, and 70% during system testing.

Coverage Metrics

The information in this paper applies tocode coverage metrics that consider control structures independently.Specifically, these are:

  • statement coverage (line coverage)
  • basic block coverage
  • decision coverage (branch coverage)
  • condition/decision coverage
  • modified condition/decision coverage (MCDC)

Although some of these metrics are less sensitive to control flow than others,they all correlate statistically at a large scale.

Formal Standards

DO-178B

The aviation standard DO-178B requires 100% code coverage for safety critical systems.This standard specifies progressively more sensitive code coverage metrics for more critical systems.

Effect of System FailureLevelExampleRequired Code Coverage
CatastrophicACrash100% modified condition/decision coverageand 100% statement coverage
HazardousBPassenger fatality100% decision coverageand 100% statement coverage
MajorCPassenger injury100% statement coverage
MinorDFlight plan changeNo code coverage requirement
No effectEEntertainment system failureNo code coverage requirement

These requirements consider neither the probability of a failure nor the cost ofperforming test cases.

IEC 61508

The standard IEC 61508:2010 "Functional Safety of Electrical/Electronic/Programmable Electronic Safety-Related Systems"recommends 100% code coverage of several metrics, but the strenuousness of the recommendation relates to the criticality.

Safety Integrity Level100% entry points100% statements100% branches100% conditions, MC/DC
1 (least critical)Highly RecommendedRecommendedRecommendedRecommended
2Highly RecommendedHighly RecommendedRecommendedRecommended
3Highly RecommendedHighly RecommendedHighly RecommendedRecommended
4 (most critical)Highly RecommendedHighly RecommendedHighly RecommendedHighly Recommended

The safety integrity level (SIL) relates to the probability of unsafe failure.Determining the SIL involves a lengthy risk analysis.

This standard recommends but does not require 100% coverage.It specifies you should explain any uncovered code.

This standard does not define the coverage metrics and does not distinguish between condition coverage and MC/DC.

ISO 26262

ISO 26262 "Road vehicles -- Functional safety" requires measuring code coverage,and specifies that if the level achieved "is considered insufficient", then a rationale must be provided.The standard recommends different coverage metrics for unit testing than for integration testing.In both cases, the strenuousness of the recommendations relates to the criticality.

For unit testing, three coverage metrics are recommended, shown in the table below.The standard does not provide definitions for these metrics.

MethodsASIL
A (least critical)BCD (most critical)
Statement coveragehighly recommendedhighly recommendedrecommendedrecommended
Branch coveragerecommendedhighly recommendedhighly recommendedhighly recommended
Modified Condition/Decision Coveragerecommendedrecommendedrecommendedhighly recommended

For integration testing, two metrics are recommended, shown in the table below.

MethodsASIL
A (least critical)BCD (most critical)
Function coveragerecommendedrecommendedhighly recommendedhighly recommended
Call coveragerecommendedrecommendedhighly recommendedhighly recommended

The standard defines function coverage as the percentage of executed software functions, and call coverage as the percentage of executed software function calls.

The automotive safety integrity level (ASIL) is based on the probability of failure, effect on vehicle controllability, and severity of harm.The ASIL does not correlate directly to the SIL of IEC 61508.

The code coverage requirements are contained in part 6 "Product development at the software level."

ANSI/IEEE 1008-1987

The IEEE Standard for Software Unit Testing section 3.1.2 specifies 100% statement coverage as a completeness requirement.Section A9 recommends 100% branch coverage for code that is critical or has inadequate requirements specification.Although this document is quite old, it was reaffirmed in 2002.

FDA requirements for Medical Devices

The United States Federal Drug Administration FDA documentGeneral Principles of Software Validation issued Jan 2002recommends structural testing but does not specify any particular code coverage requirement.The document says only:

The amount of structural coverage should be commensurate with the level of risk posed by the software.

References

Efficient use of code coverage in large-scale software development, Yong Woo Kim, 2003

Code coverage, what does it mean in terms of quality? Williams et al, 2001

An Empirical Study of the Branch Coverage of Different Fault Classes, Melissa Cline and Linda Werner, 1994

Coverage measurement experience during function test, Paul Piwowarski et al, 1993

How Do You Know When You Are Done Testing?, Richard Bender, 2000

How to Misuse Code Coverage, Brian Marick, 1997

Comparing the Effectiveness of Software Testing Strategies, Basili and Selby, 1987

Understanding the Use, Misuse and Abuse of Safety Integrity Levels, Felix Redmil, 2000

Minimum Acceptable Code Coverage (2024)

FAQs

Minimum Acceptable Code Coverage? ›

With that being said it is generally accepted that 80% coverage is a good goal to aim for. Trying to reach a higher coverage might turn out to be costly, while not necessary producing enough benefit. The first time you run your coverage tool you might find that you have a fairly low percentage of coverage.

What is minimum code coverage? ›

Code coverage of 70-80% is a reasonable goal for system test of most projects with most coverage metrics. Use a higher goal for projects specifically organized for high testability or that have high failure costs. Minimum code coverage for unit testing can be 10-20% higher than for system testing.

How much test coverage is good enough? ›

Test Coverage: Test coverage is a technique where our test cases cover application code and on specific conditions those test cases are met. Minimum Test Coverage Rate: Keeping it between 60 - 70%. Optimal Test Coverage Rate: Keeping it between 70 - 80%.

What is 80% code coverage? ›

The percentage of coverage, e.g., 80 % statement coverage, is one measure of the thoroughness of a test suite. No, it means that 80% of the code is being run by test code. They are only assuming effective tests.

Should code coverage be 100%? ›

Code coverage is a measurement of how much of your codebase is exercised by your test suite. Having 100% coverage means that every line of code is invoked when your tests are run. This is often held up as an ideal target to aim for in testing. However, 100% code coverage can be misleading and counterproductive.

What is a good amount of code coverage? ›

With that being said it is generally accepted that 80% coverage is a good goal to aim for. Trying to reach a higher coverage might turn out to be costly, while not necessary producing enough benefit.

What does minimum coverage mean? ›

Minimum coverage car insurance will help pay for the injuries and property damage you cause if you're the driver in the at-fault accident. In some states, minimum coverage car insurance also includes PIP and uninsured motorist coverage, which can help pay for your injuries in a variety of scenarios.

Is 75% code coverage good? ›

Code Coverage

You must have at least 75% of your Apex covered by unit tests to deploy your code to production environments. All triggers must have at least one line of test coverage. We recommend that you have 100% of your code covered by unit tests, where possible.

How to calculate code coverage? ›

It can be calculated using the formula: Code Coverage Percentage = (Number of lines of code executed)/(Total Number of lines of code in an application) * 100.

What is the difference between test coverage and code coverage? ›

The main difference between test coverage vs. code coverage is whether the coverage is qualitative or quantitative. While test coverage measures the quality of the testing process, code coverage measures the quantity of code that has been tested.

What is fine code coverage? ›

Fine Code Coverage is a Visual Studio Extension to Visualize unit test code coverage easily for free. Fine Code Coverage works by reacting to the visual studio test explorer, providing coverage from each test project containing tests that you have selected to run.

How to improve code coverage? ›

Write More (Useful) Tests

So given a current ratio, one can increase total coverage by by increasing the amount of covered_code. (We'll visit the topic of decreasing total_code later). The usual way to increase covered code answer is "code more tests" that exercise additional code.

What is meant by an 80 %- 20 insurance coverage? ›

Simply put, 80/20 coinsurance means your insurance company pays 80% of the total bill, and you pay the other 20%. Remember, this applies after you've paid your deductible.

How to ensure 100% test coverage? ›

How to Ensure 100% Test Case Coverage of Requirements
  1. Understanding the Requirements. ...
  2. Developing User Personas. ...
  3. Identifying Test Scenarios. ...
  4. Outlining Test Cases. ...
  5. Incorporating Different Coverage Metrics. ...
  6. Requirement-Based Coverage. ...
  7. Risk-Based Coverage. ...
  8. Boundary and Equivalence Testing.
Jan 3, 2024

How do you maximize code coverage? ›

Several Ways to Achieve Maximum Code Coverage
  1. Use automated testing tools. Automated testing tools can help you run a large number of tests in a short period. ...
  2. Write unit tests. ...
  3. Use mutation testing. ...
  4. Enable coverage tracking in your development environment. ...
  5. Review your test suite regularly. ...
Jan 3, 2023

How important is code coverage? ›

Code coverage analysis acts as a mapping system highlighting the areas explored through rigorous testing and those that remain uncharted. This insight is invaluable because it provides a tangible measure of the thoroughness of your testing efforts.

Is minimum coverage worth it? ›

Most insurance professionals recommend you consider buying higher liability coverage limits than your state's minimum, even if you choose not to have comprehensive and collision coverage on your vehicle.

What is the difference between full coverage and minimum coverage? ›

Full-coverage auto insurance includes liability coverage and covers additional damages to your vehicle in a collision, from natural forces or due to theft and vandalism. Getting the minimum liability car insurance for your state is around $1,812 cheaper per year on average but it comes with less protection.

What does code coverage mean? ›

In software engineering, code coverage, also called test coverage, is a percentage measure of the degree to which the source code of a program is executed when a particular test suite is run.

What is 75% code coverage? ›

Code Coverage

You must have at least 75% of your Apex covered by unit tests to deploy your code to production environments. All triggers must have at least one line of test coverage. We recommend that you have 100% of your code covered by unit tests, where possible.

Top Articles
International Remittance | Fees and charges - HSBC IN
How to Transfer Money from India to USA Without Tax
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Dmv In Anoka
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Umn Biology
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Rogold Extension
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Weekly Math Review Q4 3
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated:

Views: 6237

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.