Introduction To Software Testing: H El'ene WAESELYNCK
Introduction To Software Testing: H El'ene WAESELYNCK
ReSIST Courseware
Testing
ReSIST Courseware
164
Development effort:
0,1-0,5 person.year / KLOC (large software) 5-10 person.year / KLOC (critical software)
Fault density:
10-200 faults / KLOC created during development - static analysis - proof - model-checking
- testing
0,01-10 faults / KLOC residual in operation
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation
165
Test inputs
Test outputs
Oracle
Verdict
(pass/fail)
! Oracle problem = how to decide about the correctness of the observed outputs?
" Manual computation of expected results, executable specication, back-toback testing of different versions, output plausibility checks, ...
ReSIST Courseware
166
If x>0: output (x+1)/3 + 1 Else: output 0 Example_function (int x) BEGIN int y, z ; IF x ! 0 THEN z = 0 ELSE y = x-1 ; /* y = x+1 */ z = (y/3) +1 ; ENDIF Print(z) ; END ! Activation of the fault if x > 0 ! Error propagation: incorrect output if (x mod 3) ! 1 ! Violation of an oracle check:
" Expected result correctly determined by the operator # fault revealed " Back-to-back testing of 2 versions, V2 does not contain this fault # fault revealed " Plausibility check 0 < 3z-x < 6 # fault revealed if (x mod 3) = 0
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 167
REQUIREMENTS
SYSTEM TESTS
HIGH-LEVEL DESIGN
INTEGRATION TESTS
DETAILED DESIGN
UNIT TESTS
CODING
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation
168
Whatever the adopted life-cycle model, it denes a testing process, in interaction with the software development process
Planning test phases associated with development phases Progressive integration strategy (e.g., top-down design, bottom-up testing) Tester/developer independence rules (according to software phase and criticality) Rules guiding choice of test methods to employ (according to software phase and criticality) Procedures for coordinating processes
ReSIST Courseware
169
Stub
Stub
! no stub to develop " High-level components are tested late, while it may be important to test them early # because they are major components of the system (e.g., GUI)
# to reveal high-level faults (e.g., inadequate functional decomposition)
171
SELECTIVE CHOICE
RANDOM CHOICE
criterion
The model synthesizes information about the program to be tested. The criterion indicates how to exploit the information for selecting test data: it denes a set of model elements to be exercised during testing.
Deterministic: selective choice of inputs to satisfy (cover) the criterion. Probabilistic: random generation according to a probabilistic distribution over the input domain; the distribution and number of test data are determined by the criterion.
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 172
Purposes of testing
Fault nding test: test aimed at uncovering fault
Conformance test:
functional test aimed at checking whether a software complies with its specication (integrated testing level, required traceability between test data and specication) test aimed at checking the ability of a software to work acceptably in the presence of faults or of stressing environmental conditions
Robustness test:
Regression test :
after software modication, test aimed at checking that the modication has no undesirable consequence
ReSIST Courseware
173
Introduction Structural testing Functional testing Mutation analysis Probabilistic generation of test inputs
ReSIST Courseware
174
Control ow graph
Oriented graph giving a compact view of the program control structure:
built from the program source code A node = a maximal block of consecutive statements i1, in
i1 is the unique access point to the block the statements are always executed in the order i1, in the block is exited after the execution of in
Structural criteria
ReSIST Courseware
175
POWER function:
computes Z = XY, where X and Y are two integers (X! 0 )
BEGIN read (X,Y) ; W = abs (Y) ; Z = 1; WHILE (W <> 0) DO Z = Z * X ; W = W-1 ; END IF (Y<O) THEN Z = 1/Z ; END print (Z) ; END
2
W! 0 Z=Z.X W =W-1 W= 0
3 4
Y"0 print(Z) Y<0
5 Z=1/Z 6
Program execution = activation of a path in the graph Structural Criterion: guides the selection of paths
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 176
! All Paths
" Non-executable path: 1!2!4!5!6 " Innite (or very large) number of paths: number of loop iterations 2 ! (3 !2)* determined by |Y|
2
W! 0 W= 0
! All Branches
Z=Z.X W =W-1
3 4
Y"0 print(Z) Y<0
5 Z=1/Z 6
! All Statements
" Covered by a single execution Y < 0 : 1 ! 2 ! (3 ! 2)+ ! 4 ! 5 ! 6
ReSIST Courseware
177
Other criteria
Criteria for covering loops
Intermediate between all paths and all branches E.g., pick paths that induce 0, 1 and n>1 loop iterations (you may, or not, consider all subpaths for the loop body at each iteration)
Test a subset of combinations such that each condition independently affects the outcome of the decision to F and T
Principle
A A A"B
AB 0 1 2 3 FF FT TF TT
Very much used in the avionics domain: required by DO-178B for Level A software
A#B
AB FF FT TF TT
3 test cases FF FT TF
Dec. F T T T Cond. Affect. Dec. A (2), B (1) B (0) A (0)
Ex : A " (B # C)
ABC 1 2 3 4 5 6 7 8 TTT TTF TFT TFF FTT FTF FFT FFF Res. T T T F F F F F Oper. Affect. Res. A (5) A (6), B (4) A (7), C (4) B (2), C (3) A (1) A (2) A (3)
Take a pair for each operand A: (1,5) or (2,6) or (3,7) B: (2,4) C: (3,4) Hence two minimal sets for covering the criterion {2, 3, 4, 6} ou {2, 3, 4, 7} i.e., 4 cases to test (instead of 8) Generally: [n+1, 2n] instead of 2n
Remark: MC/DC can be applied to instructions involving Boolean expressions, in addition to branching conditions If (A and (B or C))
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck
Some cases may be impossible to cover when conditions are not independent
Example 1: (A " B) # A 1st occurrence of A cannot affect the decision outcome F Example 2 : (A " x # y) # (x > y-10 ) x # y cannot affect the decision outcome F
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 181
MC / DC in practice
A priori approach via complete truth table often infeasible (e.g., number of operands > 4)
ReSIST Courseware
182
Data ow
Annotating the control graph:
Node i
Def (i) = set of variables dened at node i, which can be used externally to i C-use (i) = set of variables used in a calculus at node i, not dened in i
Edge (i,j)
P-use (i, j) = set of variables appearing in the predicate conditioning transfer of control from i to j
Associated criteria
For each variable v dened in node i, selection of subpaths between this denition and one or several subsequent uses of v
ReSIST Courseware
183
1
node i 1 def(i) X, Y, W, Z c-use (i) arc (i,j) (1,2) p-use (i,j)
2
(2,3) (2,4) W W
2 3 4 5 6 Z Z Z W, Z X, W, Z
W! 0 Z=Z.X W =W-1
W= 0
3 4
Y"0 print(Z) Y<0
5 Z=1/Z 6
Example : denition of Z at node 1 --> covering all uses? use at node 3: test with |y| > 0 use at node 6: test with y = 0 use at node 5 impossible, as path 1 ! 2 ! 4 ! 5 ! 6 is infeasible
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation
184
criteria:
All denitions
Selection of a subpath for each variable denition, for some use (equally in a calculus or predicate)
All Uses
Selection of a subpath for each use
All DU paths
Selection of all possible subpaths without iteration between denition and each use
ReSIST Courseware
185
All paths
All uses
All C-Uses
ReSIST Courseware
186
Mainly applicable to the rst test phases (unit testing, integration of small sub-systems)
Complexity of analysis rapidly grows Note: for integration testing, a more abstract graph may be used (call graph)
187
Introduction Structural testing Functional testing Mutation analysis Probabilistic generation of test inputs
ReSIST Courseware
188
Consider both valid and invalid classes (robustness testing) Identify boundary values for dedicated tests
E.g., -1, 0, 1, +/- MAXINT
Example
The price entered by the operator must be a strictly positive integer. If price # 99%, then From 100% and above, the processing Valid classes: 1 # price # 99 100 # price + possibly:
ReSIST Courseware
Boundary values: price = -1, 0, 1, 98, 99, 100, 101, +/- MAXINT nothing entered ($)
Testing, Verification and Validation 189
Analysis granularity?
Separate analysis of input variables ( considering all case combinations?
For price input variable For in_stock input variable 1 # price # 99 in_stock = TRUE 100 # price in_stock = FALSE
"
ReSIST Courseware
190
Decision Table
rule 1 rule 2
LIST OF CONDITIONS C1 C2 C3 LIST OF ACTIONS A1 A2 TRUE X TRUE YES YES TRUE TRUE
rule 3
rule 4
191
Tabular representation
ReSIST Courseware
192
Tabular representation
/
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 193
spec
)/r
impl1
)/s
impl2
)/r
Generally, direct observation of state i is impossible Selective choice strategy often used:
)/r 1 */)/s 2
Input ) enabling to distinguish between ! and ": ! --> r output " --> s output */r Testing transition " )/s ! via sequence:
Reset . ) . ) . )
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 195
Generally, direct observation of state j is impossible Selective choice strategy often used:
Do not always exist { Exists for each minimal and complete MEF
- Distinguishing sequence DS (same + j) - Sequence UIO (unique for each j) - Set W (set of sequences enabling to distinguish states 2 by 2)
ReSIST Courseware
196
General case [ 1 2 n] % W = {)} [1 3] [2, 4 n] % W = {), **} [1] [3] [2, ...] [4] [5,]
1
W
)
W 2
* 1
)
W
*
W
Test tree
ReSIST Courseware
Test sequences
Testing, Verification and Validation 197
Transition tour
W method: For a completely specied, minimal, deterministic FSM of n states If implementation is also deterministic, with n states at most, the driver implements correctly the Reset, Then the W method guarantees to reveal faults producing output errors (according to the output alphabet) and transfer errors
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck
198
Transition systems
LTS (Labelled transition system) = low level formalism for describing process systems / communicating automata
Example: specications in LOTOS, SDL, Estelle, can be translated in LTS
Basic LTS: input and output events are not distinguished $ IOLTS (Input/Output LTS) for testing
ReSIST Courseware
199
Impl3 in conformity
?b ?a !z !x !c
,4 !y
200
Test cases
Test case = IOLTS with specic trap states (Pass, Fail, Inconclusive)
--> incorporates inputs, expected outputs, and verdict
Example:
?a !x ! other !y ! other FAIL
! z PASS
FAIL PASS
(Actually, the mirror image ?- ! is taken, because inputs/outputs of the system are outputs/inputs of the tester)
Test case automatically synthesized from a test purpose Test purpose =IOLTS X Spec =IOLTS Test case =IOLTS
ReSIST Courseware
201
Test purpose
handwritten automatically generated from a specication coverage criterion
Example: transition coverage of the SDL model
!z
?a !z ,1 !x ,2 ! other !y
!x !y
! other FAIL
! z INCONCL.
FAIL PASS
(Actually, the mirror image of this)
ReSIST Courseware
202
Functional Testing
No homogeneous framework, methods depend on the used model
Equivalence classes Decision tables Finite state machines Statecharts SDL Logic-based specications (algebraic, model-oriented)
Model abstraction level & criterion stringency depend on the complexity (integration level) of the tested software Formal models used for specication and design $ makes it possible to (partially) automate testing = input generation, oracle
ReSIST Courseware
203
Introduction Structural testing Functional testing Mutation analysis Probabilistic generation of test inputs
ReSIST Courseware
204
ReSIST Courseware
205
< ! #
low ! mid
& Tools Mothra (Georgia Inst. of Techn.): Fortran Sesame (LAAS): C, Pascal, Assembly, Lustre JavaMut (LAAS): Java and many others
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 206
ReSIST Courseware
207
! All paths: score < 100% ! For a given criterion, strong impact of the chosen input values ! Criterion stringency + no guarantee
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation 208
! exhaustiveness according to fault assumptions " explosion of test size in order to account for weaker assumptions
Remark: increase of the test size in both cases # Necessity to automate input selection and oracle procedure
ReSIST Courseware v. Henke, Bernardeschi, Masci, Pfeifer, Waeselynck Testing, Verification and Validation
209
Introduction Structural testing Functional testing Mutation analysis Probabilistic generation of test inputs
ReSIST Courseware
210
Probabilistic approaches
Random testing
Uniform distribution over the input domain ! Easy to implement " blind selection, usually inefcient usually not recommended!
Operational testing
Input distribution is representative of operational usage ! Removal of faults that will have the greatest impact on reliability + software reliability assessment " inadequate for revealing, or assessing the consequences of, faults that induce small failure rates (e.g., < 10-4/h)
211
Operational testing
Population of users $ test according to several operational proles Denition of operational prole(s): functional modeling
Identifying operating modes, functions which can be activated in a mode, input classes Quantifying probabilities associated to the model according to operating data for similar systems, or to projected estimates $ introducing measurement capabilities in the system ($log$ les)
ReSIST Courseware
212
Structural statistical testing Probabilitic analysis of control graph and data flow Functional statistical testing Probabilitic analysis of behavior models
Finite state machine, decision table, Statechart
ReSIST Courseware
213
Example
&
Analytical techniques B0 0 ! Y ! 99 path k1 p1 = Prob[0 # Y # 99] p2 = Prob[99 < Y # 9999] B4 B1 0 ! Y ! 9999 99 < Y ! 9999 B2 path k2
p1 = p2 = 0.5
&
ReSIST Courseware
214
Typical cases for limit value testing Compensates imperfection of structural criteria Adequate test proles
215
! adoption of weak criteria (e.g., states,...) and possibly denition of several proles ! high test quality (e.g., qN = 0.9999)
A, G, J B, , F, I H, K, L, Z
General conclusion
Numerous test methods
General approach: take a (structural or functional) model and dene model elements to be covered
Choice
Depends on available models and their complexity Complementarity of global coverage and testing of specic cases (boundary values, transient modes, ) Deterministic or probabilistic selection
217