STM Unit 2 Notes
STM Unit 2 Notes
UNIT 2
Dynamic testing: Black-Box Testing Techniques:
Black-box technique is one of the major techniques in dynamic testing for designing effective
test cases. This technique considers only the functional requirements of the software or module. In
other words, the structure or logic of the software is not considered. Therefore, this is also known
as functional testing. The software system is considered as a black box, taking no notice of its
internal structure, so it is also called as black-box testing technique.
It is obvious that in black-box technique, test cases are designed based on functional
specifications. Input test data is given to the system, which is a black box to the tester, and results
are checked against expected outputs after executing the software, as shown in Fig. 4.1.
1
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
It can be generalized that for n variables in a module, 4n + 1 test cases can be designed with
boundary value checking method.
2
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
It can be generalized that for n input variables in a module, 6n + 1 test cases can be designed
with robustness testing.
It can be generalized that for n input variables in a module, 5n test cases can be designed
with worst-case testing.
BVA is applicable when the module to be tested is a function of several independent
variables. This method becomes important for physical quantities where boundary condition
checking is crucial. For example, systems having requirements of minimum and maximum
temperature, pressure or speed, etc. However, it is not useful for Boolean variables.
Example 4.1
A program reads an integer number within the range [1,100] and determines whether it is a prime
number or not. Design test cases for this program using BVC, robust testing, and worst-case testing
methods.
Solution
(a) Test cases using BVC: - Since there is one variable, the total number of test cases will be 4n + 1
= 5.
In our example, the set of minimum and maximum values is shown below:
3
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
(b) Test cases using robust testing: - Since there is one variable, the total number of test cases
will be 6n + 1 = 7. The set of boundary values is shown below:
(c) Test cases using worst-case testing: - Since there is one variable, the total number of test
cases will be 5n = 5. Therefore, the number of test cases will be same as BVC.
Example 4.2
A program computes ab where a lies in the range [1, 10] and b within [1, 5]. Design test cases for
this program using BVC, robust testing, and worst-case testing methods.
Solution: -
(a) Test cases using BVC Since there are two variables, a and b, the total number of test cases will be
4n + 1 = 9. The set of boundary values is shown below:
4
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
(b) Test cases using robust testing: - Since there are two variables, a and b, the total number of
test cases will be 6n + 1 = 13. The set of boundary values is shown below:
(c) Test cases using worst-case testing: - Since there are two variables, a and b, the total number
of test cases will be 5n = 25.
5
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 4.3
A program reads three numbers, A, B, and C, within the range [1, 50] and prints the largest number.
Design test cases for this program using BVC, robust testing, and worst-case testing methods.
Solution
(a) Test cases using BVC: - Since there are three variables, A, B, and C, the total number of test
cases will be 4n + 1 = 13. The set of boundary values is shown below:
(b) Test cases using robust testing: - Since there are three variables, A, B, and C, the total number
of test cases will be 6n + 1 = 19.
The set of boundary values is shown below:
6
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
(c) Test cases using worst-case testing: - Since there are three variables, A, B, and C, the total
number of test cases will be 5n = 125.
The set of boundary values is shown below:
There may be more than one variable at extreme values in this case. Therefore, test cases can be
design as shown below:
7
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 4.4
8
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
9
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
10
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
11
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
There are no well-defined rules for identifying equivalence classes, as it is a heuristic process.
However, some guidelines are defined for forming equivalence classes:
If there is no reason to believe that the entire range of an input will be treated in the same
manner, then the range should be split into two or more equivalence classes.
If a program handles each valid input differently, then define one valid equivalence class per
valid input.
Boundary value analysis can help in identifying the classes. For example, for an input
condition, say 0 <= a <= 100, one valid equivalent class can be formed from the valid range of
a. And with BVA, two invalid classes that cross the minimum and maximum values can be
identified, i.e. a < 0 and a > 100.
If an input variable can identify more than one category, then for each category, we can make
equivalent classes. For example, if the input is a character, then it can be an alphabet, a
number, or a special character. So we can make three valid classes for this input and one
invalid class.
If the requirements state that the number of items input by the system at some point must lie
within a certain range, specify one valid class where the number of inputs is within the valid
range, one invalid class where there are very few inputs, and one invalid class where there are
too many inputs. For example, specifications state that a maximum of 4 purchase orders can
be registered against a product. The equivalence classes are: the valid equivalence class (1 ≤
no. of purchase orders ≤ 4), the invalid class (no. of purchase orders > 4), and the invalid class
(no. of purchase orders < 1).
If an input condition specifies a ‘must be’ situation (e.g., ‘first character of the identifier must
be a letter’), identify a valid equivalence class (it is a letter) and an invalid equivalence class (it
is not a letter).
Equivalence classes can be of the output desired in the program. For an output equivalence
class, the goal is to generate test cases such that the output for that test case lies in the output
equivalence class. Determining test cases for output classes may be more difficult, but output
classes have been found to reveal errors that are not revealed by just considering the input
classes.
Look for membership of an input condition in a set or group and identify valid (within the set)
and invalid (outside the set) classes. For example, if the requirements state that a valid
province code is ON, QU, and NB, then identify: the valid class (code is one of ON, QU, NB) and
the invalid class (code is not one of ON, QU, NB).
If the requirements state that a particular input item match a set of values and each case will
be dealt with differently, identify a valid equivalence class for each element and only one
invalid class for values outside the set. For example, if a discount code must be input as P for a
preferred customer, R for a standard reduced rate, or N for none, and if each case is treated
differently, identify: the valid class code = P, the valid class code = R, the valid class code = N,
the invalid class code is not one of P, R, N.
If an element of an equivalence class will be handled differently than the others, divide the
equivalence class to create an equivalence class with only these elements and an equivalence
class with none of these elements. For example, a bank account balance may be from 0 to Rs
10 lakh and balances of Rs 1,000 or more are not subject to service charges. Identify: the valid
class: (0 ≤ balance < Rs 1,000), i.e. balance is between 0 and Rs 1,000 – not including Rs 1,000;
13
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 4.5
A program reads three numbers, A, B, and C, with a range [1, 50] and prints the largest number.
Design test cases for this program using equivalence class testing technique.
14
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 4.6: -
15
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 4.7: -
A program takes an angle as input within the range [0, 360] and determines in which quadrant the
angle lies. Design test cases using equivalence class partitioning method.
If we want to cover every statement in the above code, then the following test cases must be
designed:
Test case 1 just skips the while loop and all loop statements are not executed. Considering test
case 2, the loop is also executed. However, every statement inside the loop is not executed. So
two more cases are designed:
These test cases will cover every statement in the code segment, however statement coverage is
a poor criteria for logic coverage. We can see that test case 3 and 4 are sufficient to execute all
the statements in the code. But, if we execute only test case 3 and 4, then conditions and paths in
test case 1 will never be tested and errors will go undetected. Thus, statement coverage is a
necessary but not sufficient criteria for logic coverage.
17
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
3. Condition Coverage: -
Condition coverage states that each condition in a decision takes on all possible outcomes at
least once. For example, consider the following statement:
In this loop statement, two conditions are there. So test cases should be designed such that
both the conditions are tested for True and False outcomes. The following test cases are
designed:
4. Decision/condition Coverage: -
Condition coverage in a decision does not mean that the decision has been covered. If the
decision
is being tested, the condition coverage would allow one to write two test cases:
But these test cases would not cause the THEN clause of the IF to execute (i.e. execution of
decision). The obvious way out of this dilemma is a criterion called decision/condition coverage.
It requires sufficient test cases such that each condition in a decision takes on all possible
outcomes at least once, each decision takes on all possible outcomes at least once, and each point
of entry is invoked at least once.
18
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Segment: - Paths consist of segments. The smallest segment is a link, that is, a single process that
lies between two nodes (e.g., junction-process-junction, junctionprocess-decision, decision-
process-junction, and decision-process-decision). A direct connection between two nodes, as in
an unconditional GOTO, is also called a process by convention, even though no actual processing
takes place.
Path segment: - A path segment is a succession of consecutive links that belongs to some path.
Length of a path: - The length of a path is measured by the number of links in it and not by the
number of instructions or statements executed along the path. An alternative way to measure
the length of a path is by the number of nodes traversed. This method has some analytical and
theoretical benefits. If programs are assumed to have an entry and an exit node, then the number
of links traversed is just one less than the number of nodes traversed.
Independent path: - An independent path is any path through the graph that introduces at least
one new set of processing statements or new conditions. An independent path must move along
at least one edge that has not been traversed before the path is defined.
4 CYCLOMATIC COMPLEXITY: -
McCabe has given a measure for the logical complexity of a program by considering its control
flow graph. His idea is to measure the complexity by considering the number of paths in the
control graph of the program. But even for simple programs, if they contain at least one cycle, the
number of paths is infinite. Therefore, he considers only independent paths.
In the graph shown in Figure 5.3, there are six possible paths: acei, acgh, acfh, bdei, bdgh,
bdfj.
In this case, we would see that, of the six possible paths, only four are independent, as the
other two are always a linear combination of the other four paths. Therefore, the number of
independent paths is 4. In graph theory, it can be demonstrated that in a strongly connected
graph (in which each node can be reached from any other node), the number of independent
paths is given by
This is called the cyclomatic number of a program. We can calculate the cyclomatic number only
by knowing the number of choice points (decision nodes) d in the program. It is given by
20
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
This is also known as Miller’s theorem. We assume that a k-way decision point contributes for
k−1 choice points.
The program may contain several procedures also. These procedures can be represented as
separate flow graphs. These procedures can be called from any point but the connections for
calling are not shown explicitly. The cyclomatic number of the whole graph is then given by the
sum of the numbers of each graph. It is easy to demonstrate that, if p is the number of graphs and
e and n are referred to as the whole graph, the cyclomatic number is given by
22
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
23
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 2
24
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
25
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 3: -
26
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
27
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
28
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
29
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 5: -
30
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
LOOP TESTING
Loop testing can be viewed as an extension to branch coverage. Loops are important in the
software from the testing viewpoint. If loops are not tested properly, bugs can go undetected. Loop
testing can be done effectively while performing development testing (unit testing by the
developer) on a module. Sufficient test cases should be designed to test every loop thoroughly.
There are four different kinds of loops. How each kind of loop is tested, is discussed below.
1. Simple loops: - Simple loops mean, we have a single loop in the flow, as shown in Fig. 5.9.
The following test cases should be considered for simple loops while testing them:
Check whether you can bypass the loop or not. If the test case for bypassing the loop is
executed and, still you enter inside the loop, it means there is a bug.
Check whether the loop control variable is negative.
Write one test case that executes the statements inside the loop.
Write test cases for a typical number of iterations through the loop.
Write test cases for checking the boundary values of the maximum and minimum number of
iterations defined (say min and max) in the loop. It means we should test for min, min+1,
min−1, max−1, max, and max+1 number of iterations through the loop.
2. Nested loops: - When two or more loops are embedded, it is called a nested loop, as shown in
Fig. 5.10. If we have nested loops in the program, it becomes difficult to test. If we adopt the
approach of simple tests to test the nested loops, then the number of possible test cases grows
geometrically. Thus, the strategy is to start with the innermost loops while holding outer loops to
their minimum values. Continue this outward in this manner until all loops have been covered.
32
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
3. Concatenated loops: - The loops in a program may be concatenated (Fig. 5.11). Two loops are
concatenated if it is possible to reach one after exiting the other, while still on a path from entry
to exit. If the two loops are not on the same path, then they are not concatenated. The two loops
on the same path may or may not be independent. If the loop control variable for one loop is
used for another loop, then they are concatenated, but nested loops should be treated like nested
only.
4. Unstructured loops: - This type of loops is really impractical to test and they must be
redesigned or at least converted into simple or concatenated loops.
2. DATA-FLOW ANOMALIES: -
Data-flow anomalies represent the patterns of data usage which may lead to an incorrect
execution of the code. An anomaly is denoted by a two-character sequence of actions. For
example, ‘dk’ means a variable is defined and killed without any use, which is a potential bug.
There are nine possible two-character combinations out of which only four are data anomalies,
as shown in Table 5.1.
It can be observed that not all data-flow anomalies are harmful, but most of them are suspicious
and indicate that an error can occur. In addition to the above two-character data anomalies,
there may be single-character data anomalies also. To represent these types of anomalies, we
take the following conventions:
~x : indicates all prior actions are not of interest to x.
x~ : indicates all post actions are not of interest to x.
34
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
35
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 1: -
Find out the define-use-kill patterns for all the variables in the source code of this application.
36
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
From the above static analysis, it was observed that static data flow testing for the variable ‘hra’
discovered one bug of double definition in line number 1.
All-du Paths (ADUP): - It states that every du-path from every definition of every variable to
every use of that definition should be exercised under some test. It is the strongest data flow
testing strategy, since it is a superset of all other data flow testing strategies. Moreover, this
strategy requires the maximum number of paths for testing.
All-uses (AU): - This states that for every use of the variable, there is a path from the definition
of that variable (nearest to the use in backward direction) to the use.
All-p-uses/Some-c-uses (APU + C): - This strategy states that for every variable and every
definition of that variable, include at least one dc-path from the definition to every predicate use.
If there are definitions of the variable with no p-use following it, then add computational use (c-
use) test cases as required to cover every definition.
All-c-uses/Some-p-uses (ACU + P): - This strategy states that for every variable and every
definition of that variable, include at least one dc-path from the definition to every
37
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
Example 1: -
38
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
39
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
40
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
REVIEW QUESTIONS: -
1. What are the types of errors detected by black-box testing?
2. Which type of testing is possible with BVA?
3. Which type of testing is possible with equivalence class partitioning?
4. A program calculates the GCD of three numbers in the range [1, 50]. Design test cases for this
program using BVC, robust testing, and worst-case testing methods.
5. A program takes as input a string (5–20 characters) and a single character and checks whether
that single character is present in the string or not. Design test cases for this program using
BVC, robust testing, and worst-case testing methods.
6.
41
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
8.
9. A program takes as input three angles and determines the type of triangle. If all the three angles
are less than 90, it is an acute angled triangle. If one angle is greater than 90, it is an obtuse
angled triangle. If one angle is equal to 90, it is a right angled triangle.
Design test cases for this program using equivalence class testing technique.
10. What is the need of white-box testing?
11. What are the different criteria for logic coverage?
12. What is basis path testing?
13. Distinguish between decision node and junction node?
14. What is an independent path?
15. What is the significance of cyclomatic complexity?
16. How do you calculate the number of decision nodes for switch-case?
17. How do you calculate the cyclomatic complexity number of the program having many
connected components?
18. Consider the program.
42
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
43
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
21.
44
Downloaded by Harsha Priya Sunkara ([email protected])
lOMoARcPSD|48526483
22.
45
Downloaded by Harsha Priya Sunkara ([email protected])