Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Code coverage
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Basic coverage criteria === There are a number of coverage criteria, but the main ones are:<ref>{{cite book | author=Glenford J. Myers | title=The Art of Software Testing, 2nd edition |publisher=Wiley | year=2004| isbn=0-471-46912-2}}</ref> * '''Function coverage'''{{snd}}has each function (or [[subroutine]]) in the program been called? * '''Statement coverage'''{{snd}}has each [[statement (computer science)|statement]] in the program been executed? * '''Edge coverage'''{{snd}}has every [[Graph theory|edge]] in the [[control-flow graph]] been executed? ** '''Branch coverage'''{{snd}}has each branch (also called the [[DD-path]]) of each control structure (such as in [[Conditional (programming)|''if'' and ''case'' statements]]) been executed? For example, given an ''if'' statement, have both the ''true'' and ''false'' branches been executed? (This is a subset of edge coverage'''.''') * '''Condition coverage'''{{snd}}has each Boolean sub-expression evaluated both to true and false? (Also called predicate coverage.) For example, consider the following [[C (programming language)|C]] function: <syntaxhighlight lang="cpp"> int foo (int x, int y) { int z = 0; if ((x > 0) && (y > 0)) { z = x; } return z; } </syntaxhighlight> Assume this function is a part of some bigger program and this program was run with some test suite. * ''Function coverage'' will be satisfied if, during this execution, the function <code>foo</code> was called at least once. * ''Statement coverage'' for this function will be satisfied if it was called for example as <code>foo(1,1)</code>, because in this case, every line in the function would be executed—including <code>z = x;</code>. * ''Branch coverage'' will be satisfied by tests calling <code>foo(1,1)</code> and <code>foo(0,1)</code> because, in the first case, both <code>if</code> conditions are met and <code>z = x;</code> is executed, while in the second case, the first condition, <code>(x>0)</code>, is not satisfied, which prevents the execution of <code>z = x;</code>. * ''Condition coverage'' will be satisfied with tests that call <code>foo(1,0)</code>, <code>foo(0,1)</code>, and <code>foo(1,1)</code>. These are necessary because in the first case, <code>(x>0)</code> is evaluated to <code>true</code>, while in the second, it is evaluated to <code>false</code>. At the same time, the first case makes <code>(y>0)</code> <code>false</code>, the second case does not evaluate <code>(y>0)</code> (because of the lazy-evaluation of the Boolean operator), the third case makes it <code>true</code>. In programming languages that do not perform [[short-circuit evaluation]], condition coverage does not necessarily imply branch coverage. For example, consider the following [[Pascal (programming language)|Pascal]] code fragment: <syntaxhighlight lang="pascal"> if a and b then </syntaxhighlight> Condition coverage can be satisfied by two tests: * <code>a=true</code>, <code>b=false</code> * <code>a=false</code>, <code>b=true</code> However, this set of tests does not satisfy branch coverage since neither case will meet the <code>if</code> condition. [[Fault injection]] may be necessary to ensure that all conditions and branches of [[exception handling|exception-handling]] code have adequate coverage during testing.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)