Escolar Documentos
Profissional Documentos
Cultura Documentos
Design
Fault Coding Fault
Error
Terminology
Error
Represents mistakes made by people
Fault
Is result of error. May be categorized as
Fault of Commission we enter something into representation that is incorrect Fault of Omission Designer can make error of omission, the resulting fault is that something is missing that should have been present in the representation
Cont
Failure
Occurs when fault executes.
Incident
Behavior of fault. An incident is the symptom(s) associated with a failure that alerts user to the occurrence of a failure
Test case
Associated with program behavior. It carries set of input and list of expected output
Cont
Verification
Process of determining whether output of one phase of development conforms to its previous phase.
Validation
Process of determining whether a fully developed system conforms to its SRS document
Fault Of Omission
Fault Of Commission
Correct portion
Classification of Test
There are two levels of classification
One distinguishes at granularity level
Unit level System level Integration level
Test methodologies
Functional (Black box) inspects specified behavior Structural (White box) inspects programmed behavior
Specified
Programmed
Test Cases
Specified
Programmed
Test Cases
Test suite is set of all test cases Test cases are not randomly selected. Instead even they need to be designed.
{(x=3, y=2); (x=2, y=3)} will suffice {(x=3, y=2); (x=4, y=3); (x=5, y = 1)} Each test case should detect different errors
White-Box Testing
Statement coverage Branch coverage Path coverage Condition coverage Data flow-based testing
Statement Coverage
Statement coverage methodology:
design test cases so that every statement in a program is executed at least once.
Example
1. 2. 3. 4. 5. 6. int f1(int x, int y){ while (x != y){ if (x>y) then x=x-y; else y=y-x; } return x; }
Branch Coverage
Test cases are designed such that:
different branch conditions is given true and false values in turn.
Example
Test cases for branch coverage can be:
{(x=3,y=3), (x=4,y=3), (x=3,y=4)}
Condition Coverage
Test cases are designed such that:
each component of a composite conditional expression given both true and false values.
Example
Consider the conditional expression ((c1.and.c2).or.c3): Each of c1, c2, and c3 are exercised at least once i.e. given true and false values.
Branch testing
Branch testing is the simplest condition testing strategy compound conditions appearing in different branch statements are given true and false values. (note: the entire condition is given true and false values, not ALL possible sub expressions)
Branch testing
Condition testing
stronger testing than branch testing:
Branch testing
stronger than statement coverage testing.
Condition coverage
Consider a Boolean expression having n components:
for condition coverage we require 2n test cases.
Path Coverage
Design test cases such that:
all linearly independent paths in the program are executed at least once.
Defined in terms of
control flow graph (CFG) of a program.
Example
int f1(int x,int y){ 1. while (x != y){ 2. if (x>y) then 3. x=x-y; 4. else y=y-x; 5. } 6. return x; }
Path
A path through a program:
A node and edge sequence from the starting node to a terminal node of the control flow graph. There may be several terminal nodes for program.
Independent path
Any path through the program:
introducing at least one new node or one new edge that is not included in any other independent paths.
It may be straight forward to identify linearly independent paths of simple programs. However For complicated programs it is not so easy to determine the number of independent paths.
Example
Cyclomatic complexity = 7 6 + 2 = 3.
Cyclomatic complexity
The cyclomatic complexity of a program provides:
a lower bound on the number of test cases to be designed to get coverage of all linearly independent paths. only gives an indication of the minimum number of test cases required.
Cyclomatic complexity
Cyclomatic complexity of a program:
also indicates the psychological complexity of a program. difficulty level of understanding the program.
Cyclomatic complexity
From maintenance perspective,
limit cyclomatic complexity
of modules to some reasonable value.
Data-flow-based Testing
Basic idea: test the connections between variable definitions (write) and variable uses (read) Starting point: variation of the control flow graph
Each node represents a single statement, not a chain of statements
Set DEF(n) contains variables that are defined at node n (i.e., they are written) Set USE(n): variables that are read
Example
Assume y is already initialized 1 s:= 0; 2 x:= 0; 3 while (x<y) { 4 x:=x+3; 5 y:=y+2; 6 if (x+y<10) 7 s:=s+x+y; else 8 s:=s+x-y; 1 2 3 4 5 6 DEF(1) := {s}, USE(1) := DEF(2) := {x}, USE(2) := DEF(3) := , USE(3) := {x,y} DEF(4) := {x}, USE(4) := {x} DEF(5) := {y}, USE(5) := {y} DEF(6) := , USE(6) := {x,y} DEF(7) := {s}, USE(7) := {s,x,y} DEF(8) := {s}, USE(8) := {s,x,y} DEF(9) := , USE(9) := DEF(10) := , USE(10) :=
7
9
10
Reaching Definitions
1 A definition of variable x at node n1 reaches node n2 if and only if there is a path between n1 and n2 that does not contain a definition of x 2 3 4
DEF(1) := {s}, USE(1) := DEF(2) := {x}, USE(2) := DEF(3) := , USE(3) := {x,y} DEF(4) := {x}, USE(4) := {x} DEF(5) := {y}, USE(5) := {y} DEF(6) := , USE(6) := {x,y} DEF(7) := {s}, USE(7) := {s,x,y} DEF(8) := {s}, USE(8) := {s,x,y}
5
6
7
9
10
Def-use Pairs
A def-use pair (DU) for variable x is a pair of nodes (n1,n2) such that
x is in DEF(n1) The definition of x at n1 reaches n2 x is in USE(n2)
DEF(1) := {s}, USE(1) := DEF(2) := {x}, USE(2) := DEF(3) := , USE(3) := {x,y} DEF(4) := {x}, USE(4) := {x} DEF(5) := {y}, USE(5) := {y} DEF(6) := , USE(6) := {x,y} DEF(7) := {s}, USE(7) := {s,x,y} DEF(8) := {s}, USE(8) := {s,x,y}
5
6
7
9
10
Data-flow-based Testing
Identify all DU pairs and construct test cases that cover these pairs
Several variations with different relative strength
All-DU-paths: For each DU pair (n1,n2) for x, exercise all possible paths n1, n2 that are clear of a definition of x All-uses: for each DU pair (n1,n2) for x, exercise at least one path n1 n2 that is clear of definitions of x
Data-flow-based Testing
All-definitions: for each definition, cover at least one DU pair for that definition
i.e., if x is defined at n1, execute at least one path n1..n2 such that x is in USE(n2) and the path is clear of definitions of x
Clearly, all-definitions is subsumed by all-uses which is subsumed by all-DU-paths Motivation: see the effects of using the values produced by computations
Focuses on the data, while control-flow-based testing focuses on the control