CSE565: Software Validation, Verification and Testing
Department of Computer Science and Engineering Ira A. Fulton School of Engineering
Arizona State University
This are my notes for the eighth class session:
1. Structure-Based Testing (White Box Testing)
- A white box testing methods gets its name due the fact it see the code. Unlike black box testing methods that are all based only in requirements.
- Tend to be techniques to be applied into lower level (small units of code) unit, services, components.
- Not for entire systems
- Not fot Integration or Qualification Level of Testing
There are two categories of structure-based Testing (white box testing): static techniques and dynamic techniques.
1.1. Static Techniques
Analysis of the code. Example: symbolic execution.
1.2. Dynamic Techniques
Execute the code: run for test. There are two types of dynamic techniques:
- Structure or control flow.
- Statement coverage
- Decision coverage
- Decision-Condition Coverage
- Multiple decision Coverage
- Data flow
2. Statement Coverage
Develop test cases such that every statement is execute at least once.
- Example:
if a <10 or b>5
(1) then x<-50 (2) else x <-0; if w = 5 or y>0
(3) then z<-48 (4) else z<-5; - Flow Chart = Control Flow Diagram.
Test predicate (diamond)
Statement (oval) - 4 statement in the previous code.
- Path Testing to execute every Path into the code!
Testing strategy execute all path into the code
- Loops are going to make the numbers of paths bigger. So path coverage is complicate.
- Values of (a, b, w, y) to execute all statements (with 2 cases we do it)!
a = 0, b=0, w=0, y=0 (execute 1 and 4)
a=10, b=4, w=5, y = don’t care (execute 2 and 3)Whit these two tests cases we are covering all the statements.
- However, this kind of testing is the minimum need.
FAA D0178B standard / best practices:
1. statements 100% statement coverage! - Compilers help us to do that. By example the PROFILER measure the time of each statement.
3. Decision (branch) Coverage
- Develop test cases such that each branch (decision point) is executed at least once.
- Decision point -> conditional statement = test predicates = diamonds
- EJEMPLO UN MAPA CUADRICULAR CON CALLES Y CADA INTERSECION ES DECIDIR UNA DIRECCION
- Even If I use structured programming (no GOTO) then if I have NOT 100% statement coverage then I have 100% test predicated.
s1
if x<10 then s2 s3
x =5
I have 100% statement coverage
But NOT 100% decision coverage, false case is MISSING! - Statement Coverage Do Not Imply Decision Coverage!
- Decision Coverage satisfies Statement but Statement not necessarily satisfies Decision!
So Software must cover 100% Decision Coverage
4. Decision-Condition Coverage
- Develop test such that each condition in a decision takes on all possible outcomes and each decision takes on all possible outcomes
- This is like Decision++ (the second part of the definition, is Decision Coverage)
if x<10 or y>50 and z!=0 or flag= T and status = NIL
then S1
else S2
2 test to statement coverage
2 test to decision coverageBut that not enough for Decision-Condition Coverage.
We need to open the test predicate and look inside: there are 5 conditions!For each condition we need to test their TRUE and FALSE cases
We need 2 cases. All false and All True.
5. Multiple Condition
- Develop test to execute all combinations of conditions within a decision.
This is the most powefull.
6. Example, Test Binary Search Algorithm)
(1) start <-1;
(2) end <-num;
(3) found <- false;
(4) while starts <= end and not found //(C1) and (C2)
(5) middle <-(start = end)/2
(6) if key > table[middle] //(C3)
(7) then start <- middle +1
(8) else if key = table[middle] //(c4)
(9) then found <-T
(10) LOC <- middle;
(11) else end <- middle -1
We have 4 conditions, and we have 11 statements (each row). We have three decision points and we have one case with multiple (2) conditions.
if4
T
F
if6
T
F
if8
T
F
For multiple-condition coverage C1 y C2 make combinations of T y F
For conditions C3 y C4 simply try one T and one F of each one
Example of Execution
10 20 30 40 50 60 70 Key=55
1
2
3
4 with T, T
5
6 T
7
4 done before T, T
5
6 F
8 with F
11
4 con T, T
5
6 T
7
4 con F, T
- Multiple-condition Coverage: 100% NO
- Decision-condition Coverage: 100% NO
- Decision Coverage: NO
- Statement coverage: NO
Now execute this:
10 20 30 40 50 60 70 Key = 40
1
2
3
4 with T, T
5
6 with F
8 with T
9
10
4 with T,F
Coverage is cumulative
4. Multiple-condition Coverage NOT 100% (75%)
3. Decision-condition Coverage 100%
2. Decision Coverage 100%
1. Statement Coverage 100%