Newsroom / Blog
Blog

What you should know about code coverage

April 3, 2019
What you should know about code coverage

Code Coverage is an important metric in embedded software development and is considered in standards like ISO 26262

  • Code Coverage is an important metric in embedded software development and is considered in standards like ISO 26262
  • Measuring all coverage and robustness goals is a comprehensive task
  • This article gives an overview of relevant test goals in respect to the risk class, development level and project needs.

Each time we talk about testing, we also talk about code coverage. But why is it important to keep an eye on code coverage and what are possible code coverage goals?

What is code coverage?

Code coverage is the sum of all coverage goals that are covered by a set of test cases. Coverage goals are e.g. statements or decisions. The ISO 26262 names coverage goals like statement, decision/branch and modified condition/decision coverage for unit testing. Depending on the risk class (=ASIL level) a subset of these coverage goals are highly recommended. Nevertheless, these coverage goals are just a subset of the available coverage goals for C Code in general. There are more coverage goals like function, function call, switch case, relation operator coverage. In addition, it is useful to consider functional scenarios, derive equivalence classes, boundary value checks or individually specified critical situations. For all the coverage goals the tester wants to achieve a high (if possible) 100% coverage. Beside the code coverage goals named before, we should consider robustness goals like division-by-zero, critical down casts, range violations and unreachability as well.

It is not easy to reach high coverage results with handwritten test cases. However, based on a technology called Model Checking it is possible to generate tests automatically and to create a mathematical proof, that a certain coverage or robustness goal can never be reached. As a result, all available coverage goals are analyzed and get reported as either covered or unreachable.

Let’s have a look on some samples of typical coverage goals. Coverage goals can have a different amount of properties that can either be covered or unreachable. For all of the coverage goals high coverage should be achieved.

Main Code Coverage goals
Extended code coverage goals

Now let’s have a look at robustness goals. For these code coverage goals an unreachable result is expected. Otherwise this might lead to unintended behavior.

Robustness code coverage goals

Of course, not all projects focus on all of these code coverage and robustness goals but a sufficient subset that fulfills the project safety goals. In general, there are three levels test goal are related to:

  • Unit Testing level with a detailed focus on the implementation and complex test goals like MC/DC.
  • Integration level that focuses on the interaction of several units and components
  • Architecture level that focuses on the whole software project and

What test goals are taken into account for each level is based on the risk class of the component and is usually defined by the customer and the quality assurance.

Code Coverage is derived with test cases. Also have a look at the blog article “ What are the differences between functional and structural test cases? “.

Senior Application Engineer Senior Business Development Manager India

I f you would like to try out our tools, we will gladly provide an eval uation licens e free of charge . Evaluations include a free launch workshop and al so provide an opportunity for you to meet one-on-one with our support and engineering teams .

Related Newsroom

Continue with Connected Topics.

All Newsroom
Keep in touch

Product, Event and Engineering Updates.