Ebook Software Testing
Ebook Software Testing
MOTIVATION:
Flow graphs
bcing an abstract representation of programs.
are
Any question about a program can be cast into an equivalent question about an
appropriate
flowgraph.
Most software development, testing and debugging tools use flow graphs analysis
techniques.
PATH PRODUCTS:
Normally flow graphs used to denote only control flow connectivity.
The simplest weight we can give to a link is a name.
Using link names as weights, we then convert the graphical flow graph into an equivalent
algebraic like expressions which denotes the set of all possible pathsfrom entry to exit for the
tlow graph.
Every link of a graph can be given a name.
The link name will be denoted by lower case italic letters.
In tracing a path or path segment through a flow graph, you traverse succession
names.
a
oflink
The name ofthe path or path segment that corresponds to those links is expressed naturally
by concatenating those link names.
For example, if you traverse links a.b,c and d along some path, the name for that path
segment is abcd. This path name is also called apath product.
eact eadf, ebct ebdt
td
Examples of paths.
PATH EXPRESSION:
Consider a pair of nodes in a graph and the set of paths between those node.
Denote that set of paths by Upper case letter such as X,Y. From Figure c, the members of
the path set can be listed as follows: ac, abc, abbc, abbbc, abbbbc.
The + sign is understood to mean "or" between the two nodes of interest, paths ac, or abc,
or abbc, and so on can be taken.
Any expression that consists of path names and "OR"'s and which denotes a set of paths
between two nodes is called a "Path Expression."
PATH PRODUCTS: The name of a path that consists of two successive path segments is
conveniently expressed by the concatenation orPath Productof the segment names
For example, if X and Y are defined as X-abcde,Y=fghij.then the path corresponding to X
followed by Y is denoted by XY abcdefghij
Similarly
YX=fghijabcde
aX aabcde
Xa-abcdea
XaX-abcdeaabcde
I f X and Y represent sets of paths or path expressions, their product represents the set of
paths that can be obtained by following every clement of X by any element of Y in all
possible ways.
For example.
X abc + def+ ghi Y =uvw +z Then.
XY abcuvw+ defuvw+ ghiuvw + abcz + defz + ghiz
If a link or segment name is repeated, that fact is denoted
by an
exponent
The exponent's value denotes the number of repetitions
al= a, a2- aa. a3 n times. Similarly, if
aaa: an= aaaa
X abcde then X1=abcde
X2- abcdeabcde = (abcde)2
e(a+b)(c+d)f-e(ac+ad+bc+bd)feacf+eadftebcf+ebdf
ABSORPTION RULE:
I f X and Y denote the same set of paths, then the union of these sets is unchanged,
consequently,
RULE 5: X+X=X (Absorption Rule)
For example,
ifX-ataatabc+abcd+defthenX+a =X+aa =X+abc =
X+abcd =X+def =X
LOOPS:
Loops can be understood as an infinite set of parallel paths. Say that the loop consists of a
single link b. then the set of all paths through that loop point is
b0+b1+b2+b3+b4+b5+.. °*°°°°°**'
Example
This potentially infinite sum is denoted by b* for an individual link and by X* when X is aa
path
This potentially infinite sum is denoted by b* for an individual link and by X* when X is a path expression.
The path expression for the above figure is denoted by the notation:
ab'eact+abctabbe+abbbe+.
Evidently. aa*=a*a=at and XX*=X*X=X+
4. Select any node for removal other than the initial or final node. Replace it with a set of
equivalent links whose path expressions correspond to all the ways you can form a product
of the set of inlinkswith the set of outlinksof that node.
5. Combine any remaining serial links by multiplying their path expressions
6. Combine all parallel links by adding their path expressions.
3 5
a
9
TOOT
m
OQQ-Q*-O
10
.Remove node 9 by applying step4 and 5 to yield,
ilh
kh
10
im
ilh
if kh
9 10
imf
9jf gkh
ilh
8 10
imt
Parallel Term: combine them to create a path expression for equivalent link whose
an path
expression is c+gkh; that is,
imf
bgif)"b(c+gkh)
3
ilh
imf
ilhd
3)bgin"bfc+gkh)d
imf
Remove the loop at node 6 to yield:
Q.APPLICATIONS:
The purpose of the node removal algorithm is to present one very generalized concept- the
path expression and way of getting it.
Every application follows this common
pattern:
Convert the program or graph into a path expression.
2. Identify a property of interest and derive an appropriate set of "arithmetic" rules that
characterizes the property.
3. Replace the link names by the link weights for the property of interest. The path
expression has now been converted to an expression in some algebra,
such as ordinary algebra, regular expressions, or boolean algebra. This algebraic expression
summarizes the property of interest over the set of all paths.
4. Simplify or evaluate the resulting "algebraic" expression to answer the question you
asked.
may have a bug. Therefore,oris also anomalous. Furthermore.ooandce, though not actual
bugs, are a waste of time and therefore should also be exanmined.
2. A tape transport can do a rewind (d), fast-forward (), read (r), write (w), stop (p), and skip
(k). There are rules concerning the use of the transport; for example, you cannot go from
rewind to fast-forward without an intervening stop or from rewind or
fast-forward to read or
write without an intervening stop. The following sequences are anomalous:df.dr.dwfd, andfr.
Does the flowgraph lead toanomalous sequences on any path? If so, what sequences and
under what circumstances?
3 The data-flow anomalies discussed in Unit 4 requires us to detect thedd,dk,kk,
andkusequences. Are there paths with anomalous data flows?
THE METHOD:
Annotate cach link in the graph with the appropriate operator or the null operator 1.
Simplity things to the extent possible, using the fact that a + a= a and 12 1 .
You now have a regular expression that denotes all the possible sequences of operators in
that graph. You can now examine that regular expression for the sequences of interest.
EXAMPLE: Let A, B, C, be nonempty sets of character sequences whose smallest string
is at least one character long. Let T be a two-character string of characters. Then if T is a
Substring of (ie., if T appears within) ABnC, then T will appear in AB2C. (HUANG's
Theorem)
A pp
B sIT
CP
T= ss
The theorem states that ss will appear in pp(srr)nrp if it appears in pp(srr)2rp.
However, let
A p t pp +
ps
B psr +
ps(r + ps)
Cp
T P4
Is it obvious that there is a p4 sequenee in ABnC? The thcorem states that we have only to
look t
(pt pp ps]psr +ps(r+ ps)|2rp
Multiplying out the espression and simplilying shows that there is no p4 sequence.
Incidentally. the above observation is an informal proof of the wisdom of' loop1ng twice
discussed in Unit 2. Because data-low anomalies are represented by two-character
scquences, it tollows the bove theorem that looping twice is what you need to do to find
such anoalies.
LIMITATIONS:
1lang's theorem can be easily generalized to cover sequences of greater length than two
characters. Beyond three characters, though, things get complex and this method has
probably reached its utilitarian limit for manual application.
There are some nice theorems for finding sequences that occur at thebeginnings and ends
of strings but no nice algorithms for finding strings buried in an expression.
Static low analysis methods can't determine whether a path is or is not achievable. Unless
the tlow analysis includes symbolic execution or similar techniques, the impact of
unachievable paths will not be included in the analysis.
The low-anomaly application, for example, doesn't tell us that there will be a flow
anomaly -it tells us that if the path is achievable, then there will be a flow anomaly. Such
analytical problems go away, of course, if you take the trouble to design routines for which
all paths are achievable.
This table helps you deal with different combination inputs with their associated outputs. Also, it is
known as the cause-effect table because of an associated logical diagramming technique called
cause-effect graphing that is basically used to derive the decision table.
Any complex business flow can be easily converted into the test scenarios & test cases
using this technique.
Decision tables work iteratively. Therefore, the table created at the first iteration is used as
the input table for the next tables. The iteration is done
only if the initial table is not
satisfactory.
Simple to understand and everyone can use this method to
design the test scenarios&
cases.
test
Itprovides complete coverage of test cases which help to reduce the rework on writing test
scenarios & test cases.
These tables guarantee that we consider every
possible combination of condition values.
This is known as its completeness property.
Forgot ?
Login
D o r t have an acCOunt? Sign Up
Error message is
displayed
H Home screen
is displayed
Now let' s understand the
interpretation of the above cases:
Case 1- Username and
password both were wrong. The user is shown an error message
Case 2-Username was correct, but the
password was wrong. The user is shown an error
message
Case 3- Username was wrong, but the password was correct. The user is shown an error
message.
Case 4- Username and password both were correct, and the user is navigated to the
homepage
So, this was an example of building a decision table in software
the end of this article. testing. with this we have come to
.
Logic-based testing is structural
testing when it's applied to
structure (e.g., control flowgraph of an implementation); it's
functional testing when it's applied to a specification.
.In logic-based testing we focus on the truth values of control flow
predicates
A predicate is implemented as a process whose outcome is a
truth-functional value.
For our purpose, logic-based testing is restricted to binary
predicates.
.We start by generating path expressions by path tracing as in
Unit V, but this time, our purpose is to convert the
path
expressions into boolean algebra, using the predicates' truth
values (e.g., A and ä) as weights.
. KV CHARTS:INTRoDUCTION:
I f you had to deal with expressions in four, five, or six variables, you could
get bogged down in the algebra and make as many errors in designing
test cases as there are bugs in the routine you're testing.
Karnaugh-Veitch chart reduces boolean algebraic manipulations to
graphical trivia.
Beyond six variables these diagrams get cumbersome and may not be
effective.
.SINGLEVARIABLE:
o Figure 6.6 shows all the boolean functions of a single variable and
their equivalent representation as a KV
chart
o The charts show all possible truth values that the variable A can
have.
o A "1" means the variable's value is "1" or TRUE. A "O" means that
the variable's value is 0 or FALSE.
o The entry in the box (0 or 1) specifies whether the function that the
LO
chart represents is true or false for that value of the variable.
oWe usually do not explicitly put in 0 entries but specify only the
conditions under which the function is true.
.TWOVARIABLES:
o Figure 6.7 shows eight of the sixteen possible functions of two
variables
AB NANO AB A Md o: 8
AB 8 nd not A A8 Amd 8
:
Figure 6.7: KV Charts for Functions of Two Variables.
O
AB AB AB AB
A ANO ONY F8 ExCLUSIvE OR
A 8 A 8
OR A IMPLIES 8
A 8 A
8MPLIES A
oThe first chart has two 1's in it, but because they are not adjacent,
each must be taken separately.
They are written using a plus sign.
o It is elear naw why there are sixteen functions of two variables
WwtaAERtrer LENTUnctions
Each BeX IA he OAEPtaerESPends. to a combination of the
varlables valHes r t corresponds of two
oThat combinatioh might or might not Be Irfthernotiao(iaDe box variables
corresponding to that combination might h¡ve a 1 or 0 entry)
Since n variables lead to 2" combinations of 0 and 1 for the
variables, and each such combination (box) can be filled or not
filled, leading to 2" ways of doing this.
o Consequently for one variable there are 22 = 4 functions, 16
functions of 2 variables, 256 functions of 3 variables, 16,384
functions of 4 variables, and so on.
Given fwo charts over the same variables, arranged the same way.
their product is the term by term product, their sum is the term by
term sum, and the negation of a chart is gotten by reversing all the
O and 1 entries in the chart.
A AB A B
OR
THREE VARIABLES:
o KV charts for three variables are shown below.
o As before, each box represents an elementary term of three
variables with a bar appearing or not appearing according to
whether the row-column heading for that box is 0 or 1.
A three-variable chart can have groupings of 1, 2, 4, and 8 boxes.
o A few examples will illustrate the principles:
8
Page 1 9
AB AD
01 1
01
AB
10 00 01
10 01
A 8C t
o Yo'll notice that there are several ways to circle the boxes into
maximum-sized covering groups.
FOUR VARIABLES AND MORE:
O The same principles hold for four and more variables.
Introduction
The finite state machine is as fundamental to software engineering as boolean algebra to logic.
State testing strategies are based on the use of finite state machine models for software structure,
software behavior, or specifications of software behavior.
Finite state machines can also be implemented as table-driven software, in which case they are a
powerful design option.
State Graphs
A state is defined as: *A combination of circumstances or attributes belonging for the time being to a
person or thing."
For example, a moving automobile whose engine is running can have the following states with respect to
its transmission.
Reverse gear
Neutral gear
First gear
Second gear
Third gear
Fourth gear
For example, a program that detccts the character sequence "ZCZC" can be in the following states.
Neither ZCZC nor any part of it has been detected.
Z has been detected.
ZC has been detected.
ZCZ has been detected
ZCZC has been detected.
None
States are represented by Nodes. State are numbered or may identified by words or whatever else is
convenient.
State Table-Examplee
inputs
STATE Z C A
NONE Z NONE NONE
Z ZC NONE
ZC ZCZ NONE NONE
ZCZ z ZCZC NONE
ZCZC ZCZC ZCZC ZcZC
Important graphs
State Bugs-Number of States
The number of states a state graph is the number of states we choose to recognize or model.
1,2
State c a n n e v e r be left, t h e initial s t a t e c a n
n e v e r b e e n t e r e d againn
The state is directly or indirectly recorded as a combination of values of variables that appear in the
data base.
For example, the state could be composed of the value of a counter whose possible values ranged
from 0 to 9, combined with the setting of two bit flags, leading to a total of 2*2*10=40 states.
The number of states can be computed as follows:
ldentify all the component factors of the state.
Identify all the allowable values for each factor.
The number of states is the product of the number of allowable values of all the factors.
Before you do anything else, before you consider one test case, discuss the number of states you
think there are with the number of states the programmer thinks there are.
There is no point in designing tests intended to check the system's behavior in various states if
there's no agreement on how many states there are.
Impossible States
Some times some combinations of factors may appear to be impossible.
The discrepancy between the programmer's state count and the tester' s state count is often due to a
difference of opinion concerning "impossible states".
A robust piece of software will not ignore impossible states but will recognize them and invoke an
illogical condition handler when they appear to have occurred.
(3
Equivalent States
Two states are Equivalent if every sequence of inputs starting from one state produces exactly the
same sequence of outputs when started from the other state. This notion can also be extended to set
of states.
a,b
Unreachable States
A n unreachable state is like unreachable code
A state that no input sequence can
reach
A n unreachable state is not
impossible, just as unreachable code is not impossible
There may be transitions from unreachable state to other states; there usually because the state
became unreachable as a result of incorrect transition.
There are two possibilities for unreachable states:
There is a bug; that is some transitions are missing.
The transitions are there, but you don't know about it.
Dead States
A dead state is a state that once entered cannot be left
This is not necessarily a bug but it is suspicious.
Output Errors
If a routine is specitied as a state graph that has been verified as correct in all details. Program code
or table or acombination of both must still be implemented
A bug can symptoms
manifest itseif as one of the following
Wrong number of states.
Wrong transitions for a given state-input combiation
Wrong output for a given transition.
Pairs of states or sets of states that are inadvertently made equivalent.
States or set of states that are
split to create in equivalent duplicates.
States or sets of states that have become
dead.
States or sets of states that have become
unreachable.
Principles of State Testing
The strategy for state
testing is
analogous to that used for path testing flow graphs.
Just as it's
impractical to go through every possible path in a flow graph, it's impractical to
through every path ina state graph. go
The notion of
coverage is identical to that used for flow graphs.
ven though more state
testing is done as a single case in a grand tour, it's impractical to do it that
way for several reasons.
In the early
phases of testing, you will never complete the grand tour because of
Later, maintenance, testing
in bugs.
have to be tested. A
objectives are understood, and
only a few of the states and transitions
grand tour is waste of time.
Theirs is no much
history in a long test sequence and so much has happened that verification is
difficult.
Tool Building
If you build test tools or want to know how they work, sooner or later you will be implementing or
investigating analysis routines based on these methods.
It is hard to build algorithms over visual graphs so the properties or graph matrices are fundamental
to tool building.