Module 5
Module 5
Example
Consider a program for the determination of the nature of roots of a quadratic equation. Its input is a
triple of positive integers (say a,b,c) and values may be from interval [0,100]. The program output
may have one of the following words.
[Not a quadratic equation; Real roots; Imaginary roots; Equal roots]
Design the boundary value test cases.
Solution
Quadratic equation will be of type:
ax 2 +bx+c = 0
Roots are real if (b 2 -4ac) > 0
Roots are imaginary if (b 2 -4ac) < 0
Roots are equal if (b 2 -4ac) = 0
Equation is not quadratic if a = 0
Robustness Testing
It is nothing but the extension of boundary value analysis. the extreme values are exceeded with a
value slightly greater than the maximum, and a value slightly less than minimum. This type of
testing is common in electric and electronic circuits. This form of boundary value analysis is called
robustness testing and is shown in fig. 8.6
Hence total test cases in robustness testing are 6n+1, where n is the number of input variables. So,
13 test cases are:
(200,99), (200,100), (200,101), (200,200), (200,299), (200,300)
Worst-case Testing
In it more than one variable has an extreme value. It is more thorough in the sense that boundary
value test cases are a proper subset of worst case test cases. It requires more effort. Worst case
testing for a function of n variables generate 5n test cases as opposed to 4n+1 test cases for
boundary value analysis. Our two variables example will have 52 =25 test cases and are given in
table 1.
Table 1: Worst cases test inputs for two variables example
Most of the time, equivalence class testing defines classes of the input domain.However,
equivalence classes should also be defined for output domain. Hence, we should design equivalence
classes based on input and output domain.
Consider the program for the determination of nature of roots of a quadratic equation as explained
in example 8.1. Identify the equivalence class test cases for output and input domains.
Solution
Output domain equivalence class test cases can be identified as follows:
O1={<a,b,c>:Not a quadratic equation if a = 0}
O1={<a,b,c>:Real roots if (b2-4ac)>0}
O1={<a,b,c>:Imaginary roots if (b2-4ac)<0}
Here test cases 5 and 8 are redundant test cases. If we choose any value other than nominal, we may
not have redundant test cases. Hence total test cases are 10+4=14 for this problem.
Myers explained this effectively with following example. “The characters in column 1 must be an A
or B. The character in column 2 must be a digit. In this situation, the file update is made. If the
character in column 1 is incorrect, message x is issued. If the character in column 2 is not a digit,
message y is issued”.
2. Inclusive constraint or I-constraint: This constraint exists between causes. It states that atleast
one of c1, c2 and c3 must always be 1, i.e., c1, c2 and c3 cannot be 0 simultaneously.
3. One and Only One constraint or O-constraint: This constraint exists between causes. It states
that one and only one of c1 and c2 must be 1.
4. Requires constraint or R-constraint: This constraint exists between causes. It states that for c1
to be 1, c2 must be 1. It is impossible for c1 to be 1 and c2 to be 0.
5. Mask constraint or M-constraint: This constraint exists between effects. It states that if effect
e1 is 1, the effect e2 is forced to be 0.
DD path graph:- The second step of path testing is to draw a DD path graph from the flow graph.
The DD path graph is also known as decision to decision path graph. Here the nodes of flow graph ,
which are in a sequence are combined into a single node and is called decision node.
Independent paths:- Independent paths are finding from DD path graph. An independent path is
any path through the DD path graph that introduces at least one new set of processing statements.
We should execute all independent paths at least once during path testing.
Independent paths are used in order to ensure that
a) Every statement in the program has been executed at least once.
b) Every branch has been exercised for true and false conditions
Flow Graph
DD path graph
DD path graph
Flow graph nodes DD path graph corresponding nodes
1-5 n1
6 n2
7 n3
8,9 n4
10 n5
11,12 n6
Independent paths
n1, n2, n3, n5, n6
n1, n2, n4, n5, n6
5.4.2 Cyclomatic Complexity
The cyclomatic complexity is also known as structural complexity because it gives internal view of
the code. This approach is used to find the number of independent paths through a program.
Cyclomatic complexity can be calculated by any of the three methods.
1. V(G) = e – n + 2P
e – edges
n – nodes.
P- Connected Components
2. V(G) = π + 1
Where π is the number of predicate nodes contained in the flow graph G. The only restriction is
that every predicate node should have two outgoing edges i.e., one for “true” condition and another
for “false” condition.
3. Cyclomatic complexity is equal to the number of regions of the flow graph.
Example
Consider a flow graph given below, calculate the cyclomatic complexity by all three methods.
1. V(G) = e – n + 2P
= 13 – 10 + 2 = 5
2. V(G) = π + 1
=4+1=5
3. V(G) = number of regions
=5
Therefore, complexity value of a flow graph in above Fig. is 5.
If we assign weight to each entry in the graph matrix it can be used for evaluating useful
information required during testing. If there is a connection then the weight is 1, otherwise 0. A
matrix with such weights is called a connection matrix. The connection matrix is used to find
cyclomatic complexity.
The connection matrix for Fig.24 (c) is obtained by replacing each entry with 1, if there is a link and
0 if there is no link. As usual to reduce clutter we do not write down 0 entries and this matrix is
shown in Fig
Consider the program given in Fig. 20 for the classification of a triangle. Its input is a triple of
positive integers (say a,b,c) from the interval [1,100]. The output may be:
[Scalene, Isosceles, Equilateral, Not a triangle, Invalid inputs].
Find all du-paths and identify those du-paths that are definition clear.
Solution
Step I: The program flow graph is given in Fig. 20 (a). The variables used in the program are a,b,c,
valid input.
Step II: DD Path graph is given in Fig. 20(b). The cyclomatic complexity of this graph is 7 and thus,
there are 7 independent paths.
Step III: Define/use nodes for all variables are given below:
Variable Defined at node Used at node
a 5 10, 11, 19, 22
b 7 10, 11, 19, 22
c 9 10, 11, 19, 22
Validinput 3, 12, 16 18, 29
Step IV: The du-paths are identified and are named by their beginning and ending nodes using Fig.
20 (a).
Hence total du-paths are 18 out of which four paths are not definition clear.
The changes made in the mutant program should be kept extremely small that it does not affect the
overall objective of the program. Mutation Testing is also called Fault-based testing strategy as it
involves creating a fault in the program and it is a type of White Box Testing which is mainly used
for Unit Testing.
Mutation was originally proposed in 1971 but lost forever due to the high costs involved. Now,
again it has picked steam and is widely used for languages such as Java and XML.
How to execute Mutation Testing?
Value mutations
In this, the values will modify to identify the errors in the program, and generally, we will change
the following:
• Small value à higher value
• Higher value à Small value.
For Example:
Statement Mutations
Statement mutations means that we can do the modifications into the statements by removing or
replacing the line as we see in the below example:
In the above case, we have replaced the statement r=15 by s=15, and r=25 by s=25.
Advantages and disadvantages of Mutation Testing
Advantages of Mutation Testing:
• It brings a good level of error detection in the program.
• It discovers ambiguities in the source code.
Disadvantages of Mutation Testing:
• It is highly costly and time-consuming.
• It is not able for Black Box Testing.
5.5 Levels of Testing
There are 3 levels of testing:
i. Unit Testing
ii. Integration Testing
iii. System Testing
2. The module is small enough that we can attempt to test it in some demonstrably exhaustive
fashion.
3. Confusing interactions of multiple errors in different parts of software are eliminated.
There are problems when running a module in isolation. They are
a) there is no calling statement to call it
b) this module is not calling any other module
c) the intermediate values obtained during execution can not be given as output
To overcome these problems we use driver routine which has some code to call the testing module.
And we use simple stubs that has some code and called by the testing module. Also we insert some
output statements. This overhead code, called scaffolding represents effort that is important to
testing , but does not appear in the delivered product.
The white box testing approaches are used for unit testing.