FIT4004 Lecture Notes - Lecture 5: Code Coverage, Code Smell

31 views5 pages
Week 5 + 7 - White-box/Structural testing
AKA glass-box testing
Definition: Select test cases based on structure of source code (Code doesn’t tell you
expected behaviour!)
White-box testing techniques:
Statement coverage testing
Select set of tests such that all statements are executed at least once
Example 1:
def sillyfunction(a, b):
print("a = {}, b={}".format(a,b))
if a > b:
print("{} is greater than {}".format(a, b))
Input to sillyfunction(a, b): a=2, b=1
Expected output: “2 is greater than 1” is printed
achieves 100% coverage but isn’t a good test suite. Doesn’t test a<b
or a = b 
Example 2:
def potato(a, b):
if(a || b))
test1 = true;
else
if(c)
test2 = true
Need at least 2 test cases
1. Input: a=true, b=false, Output: test1 = true
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
2. Input: a=false, b=false, c = true Output: test2 = true
Branch Coverage
Must write enough test cases that each decision has a true and a false outcome at least
once. In other words, each branch direction must be traversed at least once
Branches = if, while for, do-while
Example 1:
i. Input to sillyfunction(a, b): a=2, b=1 Expected output: “2 is greater
than 1” is printed
ii. Input to sillyfunction(a, b): a=1, b=2 Expected output: "a=1, b=2" is
printed
Example 2:
i. Input: a=true, b=false, Output: test1 = true
ii. Input: a=false, b=false, c = true Output: test2 = true
iii. Input: a=false, b=false, c = false Output: NOTHING
Easy to identify all branches and wing the testing
It is possible to have infeasible branches
Control Flow graph (cfg) - used to get branch coverage.
For each decision point:
Identify paths through cfg pi that gets you there
Write down path constraints for each pi
Identify all outward edges coming out of the decision points
Write down the edge constraint for each edge
Solve a complex constraint which says “find an input that gets me to the node,
and causes the branch to be taken”
If found, cross it and any other branches it takes along the way off the list
Repeat until out of edges coming out of decision points
Condition Coverage
For each condition, have a test case that makes a statement true and a test case that
makes a statement false
Condition coverage doesn’t guarantee decision/branch coverage
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents