0% found this document useful (0 votes)
44 views42 pages

White Box 2

The document discusses data flow testing as a white box testing method that utilizes control flow graphs to identify anomalies affecting data. It outlines the importance of defining and using variables in code, and introduces coverage criteria such as DU pairs, DU paths, and definitions to ensure thorough testing. Additionally, it covers loop testing techniques and their significance in identifying performance issues and bugs in loop constructions.

Uploaded by

lidijarasic1307
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views42 pages

White Box 2

The document discusses data flow testing as a white box testing method that utilizes control flow graphs to identify anomalies affecting data. It outlines the importance of defining and using variables in code, and introduces coverage criteria such as DU pairs, DU paths, and definitions to ensure thorough testing. Additionally, it covers loop testing techniques and their significance in identifying performance issues and bugs in loop constructions.

Uploaded by

lidijarasic1307
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

STUDY IN ENGLISH

STUDY IN ENGLISH

White box techniques


Miodrag Zivkovic

www.study.singidunum.ac.rs
STUDY IN ENGLISH

Data flow testing

• Problems with CFG techniques described up to now?


• Statement coverage and decision coverage can miss
some errors in the code
• Complete path coverage can lead to very high number
of tests (often not practical)
• Just some of those paths can expose additional errors
• How to differentiate and choose important paths?
STUDY IN ENGLISH

Data flow testing

• Intuition – statements in the code interact between


themselves through data flow
• Data value is calculated in one, and used in another
statement
• Wrong calculation in one statement can be exposed
and detected only when another statement use
that calculated value
STUDY IN ENGLISH

Data flow testing

• Data flow testing uses control flow graph (CFG) to


detect anomalies which can affect data
• Analysis of those anomalies leads to new strategies
to select test paths in such way to fill the gap
between complete path coverage (too complex)
and statement and decision coverage (usually too
simple)
STUDY IN ENGLISH

Data flow testing

Value x in statement 6
is calculated either in 1
or in 4

Bad calculation can be


detected only in 6
STUDY IN ENGLISH

Data flow testing

• Data flow testing belongs to the white box testing


methods
• When we select paths for testing, we take into
account locations where we assign values to the
variables, and locations where these variables are
used
• This technique is very useful for selecting paths in
programs with nested if statements and nested
loops
STUDY IN ENGLISH

Data flow testing

• Categories which describe state of the data


(variable):
1.D – defined, created, initialized
2.U – used
• In calculation
• As condition predicate
STUDY IN ENGLISH

Data flow testing

• Data is considered to be defined in the following


cases:
• Declaration
• Assignment of the new value
• Opened file
• Dynamically allocated
• …
STUDY IN ENGLISH

Data flow testing

• Data is considered to be used if it is a part of


calculation or predicate
• Variable is used in calculation (c) if it is located on
the right side of the assignment statement
• Variable is used as a predicate (p) if it is located in
the condition predicate
STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing


• Example – show definitions and uses in the following
program
STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing

• (1, 6) and (4, 6) are


def – use pairs

• Definitions in 1, 4
• Use in 6
STUDY IN ENGLISH

Data flow testing

• DU pair: a pair of definition and use for some


variable, such that at least one DU path exists from
the definition to the use
• DU path: a definition-clear path on the CFG starting
from a definition to a use of a same variable,
without additional definitions (changing value of
the variable)
STUDY IN ENGLISH

Data flow testing

• Two paths, 1,2,3,5,6


and 1,2,4,5,6
STUDY IN ENGLISH

Data flow testing

• 1,2,3,5,6 is a path without additional definitions,


between statements 1 and 6
• There is no additional change of the value of the
variable x
• 1,2,4,5,6 is not a path without additional definitions
• Value x is changed in 4
• (1,6) is a DU pair because at least one path without
additional definitions of x exists - 1,2,3,5,6
STUDY IN ENGLISH

Data flow testing

• Several coverage criteria exist


• The most important are:
• All DU pairs: each DU pair is exercised with at least one
test (another name is all uses)
• All DU paths: every simple path is exercised at least
once (simple path – no loop)
• All definitions: For each definition, there is at least one
test case which exercises a DU pair containing it (Every
computed value is used somewhere)
STUDY IN ENGLISH

Data flow testing

• All DU pairs (all uses)


• Tests must cover:

• Def 1, use 6
• Def 1, use 7
• Def 4, use 6
• Def 4, use 7
STUDY IN ENGLISH

Data flow testing

• All DU paths
• Tests must cover:

• Def 1, use 9 (through 7)


1-2-3-5-6-7-9
• Def 1, use 9 (through 8)
1-2-3-5-6-8-9
• Def 4, use 9 (through 7)
4-5-6-7-9
• Def 4, use 9 (through 8)
4-5-6-8-9
STUDY IN ENGLISH

Data flow testing

• All definitions
• We must cover:

• Def 1, use 6
OR
Def 1, use 7

• Def 4, use 6
OR
Def 4, use 7
STUDY IN ENGLISH

Data flow testing

• Two types of data uses


• Use is called predicate (p-use) if it appears in
predicate expression of some control flow
statement (if, while…)
• Otherwise, it is called computational
(computational use or c-use)
• Each is a subset of DU pairs (all uses)
• All p-uses + all c-uses = all DU pairs (all uses)
STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing

• All definitions – 100% coverage if we execute at least one


DU pair which contains it
STUDY IN ENGLISH

Data flow testing


• All DU pairs – 100% coverage, if each DU pair is covered at
least once
STUDY IN ENGLISH

Data flow testing

• All DU paths
• 100% coverage – every simple path from each definition to
all uses of that definition is executed
• Simple path in CFG – every part of the path is visited
minimal number of times (i.e. open paths, 1 iteration
through the loop etc.)
• On the previous example, except the paths covered with
tests for all DU pairs, there are two more paths
0-1-4-5-9-10 and 1-4-5-9-10
• It is not possible to cover them with tests
STUDY IN ENGLISH

Data flow testing

• As we have mentioned, there are several other strategies besides


the three most general strategies which have already been
described (all definitions, DU pairs, DU paths)
• Based on the type of use (p-use and c-use):
1.All p-uses coverage
2.All c-uses coverage
3.All c-uses, some p-uses
4.All p-uses, some c-uses
• Subset of DU pairs coverage
• DU pairs coverage = coverage of all p and c uses
STUDY IN ENGLISH

Data flow testing

• All p-uses
STUDY IN ENGLISH

Data flow testing

• All c-uses
STUDY IN ENGLISH

Data flow testing

• In some research different testing strategies were


compared on the set of 14 Kernighan and Plauger
programs
• This is a set of mathematical programs with known
bugs often used for testing strategy evaluation
• Data flow testing detects more bugs compared to
decision coverage
STUDY IN ENGLISH

Data flow testing


STUDY IN ENGLISH

Data flow testing

• All uses testing (DU pairs) has the best results in


practice, and it is the best value for money
• In practice, it has in average two times more
required tests compared to the decision coverage,
but with much better results
• It is important to understand that data is equally
important as the code
• Data flow testing fills the gap between decision
coverage and complete path coverage
STUDY IN ENGLISH

Testing loops

• Testing form which completely focuses on the validity of the loop


constructions
• Technically, it falls into white box testing, more precisely CFG
methods
• Loop Testing is done for the following reasons

• Testing can fix the loop repetition issues


• Loops testing can reveal performance/capacity bottlenecks
• By testing loops, the uninitialized variables in the loop can be
determined
• It helps to identify loops initialization problems.
STUDY IN ENGLISH

Testing loops

• Types of loop Tested


• Examples of types of loop tested are:
• Simple loop
• Nested loop
• Concatenated loop
• Unstructured loop
• While testing loop, it has to be checked at three
different levels:
• When loop is entered
• During its execution and
• When the loop is left
STUDY IN ENGLISH

Testing loops

• A simple loop is tested in the following way:


• Skip the entire loop
• Make 1 passes through the loop
• Make 2 passes through the loop
• Make a passes through the loop where a<b, b is the
maximum number of passes through the loop
• Make b, b-1; b+1 passes through the loop where "b" is
the maximum number of allowable passes through the
loop.
STUDY IN ENGLISH

Testing loops
• Complex loops

Concatenated nested unstructured


STUDY IN ENGLISH

Testing loops

• Nested loops
• For testing nested loops it is not feasible to apply simple
loop technique, as it would lead to geometric expansion of
the number of tests
• For nested loop, you need to follow the following steps.
• Set all the other loops to minimum value and start at the innermost
loop
• For the innermost loop, perform a simple loop test and hold the
outer loops at their minimum iteration parameter value
• Perform test for the next loop and work outward.
• Continue until the outermost loop has been tested.
STUDY IN ENGLISH

Testing loops

• Concatenated loops
• In the concatenated loops, if two loops are
independent of each other then they are tested using
simple loops or else test them as nested loops.
• Unstructured loops
• Considered to be bad programming issue. For
unstructured loops, it requires restructuring of the
design to reflect the use of the structured programming
constructs.
STUDY IN ENGLISH

Testing loops

• Limitations in Loop testing


• Loop bugs show up mostly in low-level software
• The bugs identified during loop testing are not very
subtle
• Many of the bugs might be detected by the
operating system as such they will cause memory
boundary violations, detectable pointer errors, etc.

You might also like