Testing App Unti Ghezzi
Testing App Unti Ghezzi
Software engineering
Verification in engineering
• Programs do not display a “continuous”
• Example of bridge design behavior
• One test assures infinite correct situations • Verifying the function in one point does not
tell us anything about other points
– Example 1
...
a = … / (x +20) ...
...
Any value of x is ok, except for x = -20!
Goals Definitions
• TESTING • Test case t
– Try to increase the probability that the presence – an element of D
of an error results in a failure • Test set T
• DEBUGGING – a finite subset of D
– Try to identify faults as early as possible • Test is successful if P(t) is correct
• Test set successful if P correct for all t in T
Warning: definitions are not standardized!
Statement Coverage
Statement coverage
int select(int A[], int N, int X) i=0
{
• Select a test set T such that every int i=0;
while (i<N and A[i] <X)
statement in P is executed at least once by {
i<N and A[i] <X
True
some d in T if (A[i]<0) False
A[i]<0
A[i] = - A[i]; True
– each Di is the set of data that execute i++; False
A[i] = - A[i];
}
statement i return(1); return(1)
– we should try to minimize the number of Di } i++
to make a partition One test datum (N=1, A[0]=-7, X=9) is enough to guarantee statement
coverage of function select
Faults in handling positive values of A[i] would not be revealed
We must add a test datum (N=1, A[0]=7, X=9) to cover branch False of
the if statement. Faults in handling positive values of A[i] would be
revealed. Faults in exiting the loop with condition A[i] <X would not be
revealed
Carlo Ghezzi--SE-Verif 25 Carlo Ghezzi--SE-Verif 26
Condition Coverage
Condition coverage criterion
int select(int A[], int N, int X) i=0
{
• Select a test set T such that all possible int i=0;
while (i<N and A[i] <X) i<N and A[i] <X
values of the constituents of compound { True
False
conditions are exercised at least once if (A[i]<0) A[i]<0
True
A[i] = - A[i];
i++; False
A[i] = - A[i];
}
return(1)
return(1);
} i++
Both conditions (i<N), (A[i]<X) must be false and true for different tests.
In this case, we must add tests that cause the while loop to exit for a
value greater than X. Faults that arise after several iterations of the loop
would not be revealed.
Carlo Ghezzi--SE-Verif 27 Carlo Ghezzi--SE-Verif 28
Path Coverage
Path coverage criterion
int select(int A[], int N, int X) i=0
{
• Select a test set T which traverses all paths int i=0;
while (i<N and A[i] <X)
from the initial to the final node of P’s {
i<N and A[i] <X
True
control flow if (A[i]<0) False
A[i]<0
A[i] = - A[i]; True
– all paths is unfeasible, must specify conditions i++; False
} A[i] = - A[i];
return(1); return(1)
} i++;
Symbolic execution
• Propagates the symbolic values of vars over
each execution paths Black box testing
• Symbolic state:
<path-condition, symbolic bindings>
derive test sets from specifications
• Synthesizing a patch condition means
finding values which would imply
executing that path
A possible solution
• Did you consider at least the following cases: A possible solution (cont.)
• extracting an event before any insertion
• inserting only events with different time-stamps out
• extracting more events than previously inserted
of time-stamp order
• extracting the only event in a queue
• inserting at least two events with the same time-
• many insertions followed by exactly the same number stamp without interleaving events
of extractions
• inserting at least two events with the same time-
• many alternate insertions/extractions stamp with interleaving events
• inserting as many events as the capacity (if defined) • insert/extract in/from a non initialized queue (in
• inserting more events than the capacity (if defined) some languages, e.g., Java, may not be possible)
• inserting only events with different time-stamps in • ....
time-stamp order
B * *
action
p b i b i b i b,i b,i
E=I
A p
SE = B N c c
O D
SE = I R
SE = B + I requires
one and only a masks
one a a
E A
• Generate all possible input combinations
E=B
N
D
i and check outputs
SE
m
• May reduce the number by going
m
E=I backwards from outputs
A p
SE = B N – OR node with true output:
O D
SE = I R • use input combinations with only one true input
SE = B + I – AND node with false output:
X m Y = X implies not Y • use input combinations with only one false input
Software Inspection:
Low tech but effective
• Fagan Code Inspections
– One of many “walk-through” and inspection
techniques; among the most successful
Software Inspections • More formal and well-defined than “structured
walk-throughs” etc.