terça-feira, 13 de junho de 2017

SW Testing: Code coverage criteria (including MC/DC)

The Short Story

Just a sum-up of coverage criteria (software testing):
Code coverage - Wikipedia

The Long Story

Besides coding, you might get asked to provide several types of coverage of your code (the evidences to provide to your contractor could be test report deliverables, besides the [automated] test scripts and the written test specs/procedures). The more safety-critical is your code the more criteria you will be mandated to execute (the QA / PA standards refer to these issues):
  • Function coverage – Has each function (or subroutine) in the program been called?
  • Statement coverage – Has each statement in the program been executed?
  • Branch coverage – Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? For example, given an if statement, have both the true and false branches been executed? Another way of saying this is, has every edge in the program been executed?
  • Condition coverage (or predicate coverage) – Has each Boolean sub-expression evaluated both to true and false?
  • MC/DC (Modified condition/decision coverage): A combination of function coverage and branch coverage is sometimes also called decision coverage. This criterion requires that every point of entry and exit in the program has been invoked at least once, and every decision in the program has taken on all possible outcomes at least once. In this context the decision is a boolean expression composed of conditions and zero or more boolean operators. This definition is not the same as branch coverage, however, some do use the term decision coverage as a synonym for branch coverage.
  • (and more, see Wikipedia)
  • Usage in the software industry: Code coverage is one consideration in the safety certification of avionics equipment. The guidelines by which avionics gear is certified by the Federal Aviation Administration (FAA) is documented in DO-178B and the recently released DO-178C.
  • Code coverage is also a requirement in the automotive safety standard ISO 26262 Road Vehicles - Functional Safety (part 6).
  • Sources: The oldie but goldie "The Art of Software Testing" with its orange cover (initial editions); Wikipedia.

From these verification activities, you might get to conclude that there are unreachable parts of code (typically to be removed) or that your code is far too complex to cover and needs simplification, i.e. refactoring. This is why cyclomatic complexity - and other KPIs/software metrics - is limited by some standards also at certain component criticality levels.