Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Code coverage
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Code coverage
(section)
Add topic