oose unit5-1
oose unit5-1
In terms of software quality, the software must conform to both functional and non-functional
requirements specified by the customer or user. For example, if two cars meet their specified
speed, standard, style and performance, then they are said to meet the specified requirements.
If the product meets the customer’s requirements, the customer feels satisfied and the product is
expected to be of high quality. The goal of software quality is to determine:
1. How well is the design of the software?
2. How well the software conforms to the developed design?
287
288 Object-Oriented Software Engineering
7. Supplier control
8. Training
9. Documentation
10. Safety and security
The software development life cycle consists of various phases that divide the software
development work into various parts. The software development life cycle phases are given
below:
1. Requirement analysis phase—gathering and documentation of requirements.
2. Design phase—preliminary and detailed design of the software.
3. Implementation and unit testing phase—development of source code and initial testing
of independent units.
4. Integration and system testing phase—testing the integrated parts of various units and
the system as a whole.
5. Operational phase—delivering and installing the software at the customer’s site.
6. Maintenance phase—removing defects, accommodating changes and improving the
quality of the software after it goes into the operational phase.
These phases are non-overlapping (e.g. waterfall model) or overlapping and incremental (e.g.
unified process model), depending on the type of the software development life cycle model
being used.
The elements of the quality system are related with the phases of software development
life cycle and these associations are shown in Figure 8.2. The associations depict the period
for which the element of the quality system is more closely related to the phases of software
development life cycle.
Software Testing
Software testing increases the confidence in the software by assuring that the requirements have
been met. It includes both the verification and validation activities. The basic testing (refer to
Chapter 6) consists of test planning, test cases, test design and procedures, and test reports.
Test planning starts in parallel to requirement phases of software development. The test cases
to be used in acceptance testing are also generated in this phase. By generating test cases in the
requirements phase, the requirements are verified whether they are testable or not. Each test case
includes inputs, expected results and test case pass/fail details. Test design and procedure guides
the execution of testing.
The validation testing begins as soon as the source code is available for execution. The
results generated are properly documented and recorded. Any unexpected result needs further
corrective action. Finally, the acceptance testing is carried out by the user.
Configuration Management
The management of changes is very important to ensure that the state in which the software is
in is known at any given stage in the software development life cycle. It consists of identification
and record of each item of the software. This helps in keeping track of each software item at any
point of time in the project. Thus, the correct version of the software item is always known. Any
change in the document or source code is assigned a new identifier.
The configuration management also involves approving the changes suggested by anyone
during the software development. This prevents unauthorized changes being made in the software.
Thus, each change that is necessary is implemented as we move ahead in the software development
life cycle. The configuration management activities are addressed in detail in Chapter 10.
Supplier Control
The software that is purchased by a supplier must be assured in terms of quality. The purchased
software should meet the software requirements.
Training
Training involves educating the developer about a new technique or tool or training the users
about the software operation and use.
The quality of the software can only be assured when the developers are trained on the
various technologies or tools to be used in the project. For example, if the project requires the
use of Rational Rose software for analysis and design purpose, then the designers must be taught
Software Quality and Metrics 295
about its use before the beginning of the analysis and design of the software. Similarly, the use
of testing tools, debugging tools, documentation standards, platforms, etc. must be taught before
they can be applied in the software development.
Once the software has been developed, the user must also be trained about the objectives
and use of the software. The purpose of user interfaces, navigation items in the software,
installation procedure of the software, data entry provisions, report generation mechanisms,
system administration part, etc. must be taught to the user. In addition, all the things required to
promote the effective use of the software must be explained to the user.
The system administrator must be taught of the environment in which the system must
run, hardware requirements of the software, handling of unexpected or exceptional event and
recovering from any failure. Security and backup mechanisms must also be explained to the
system administrator.
The software quality professional must always keep themselves updated about any need
of training of developer or users of the software. The software quality professional must also
keep informing the higher authorities about the requirement of any training session to meet the
quality of the software.
Documentation
Documentation is a very important part of the quality system. During the software development
phases, the SRS document, SDD, test plans and test cases, user manuals and system guides, etc.
must be produced. The specified documentation standards must be followed in order to create
these documents. The documentation helps strongly in the debugging process and hence the
maintenance of the product.
The documentation done in the requirement phase guides the design process and the
documentation done in the design phase serves as the basis of implementation of the software.
The documentation in the source code enhances its readability and understandability and helps
in debugging activities. The minimum documents that must be produced by any software under
development are given in Table 8.4.
Table 8.4 Recommended documentation for a software
S. No. Document name
1 Software requirement specification
2 Software design description document
3 Test plans
4 Test cases
5 Test reports
6 Risk management plan
7 User manual
8 Operation manual
9 Installation guide
The safety critical software is that whose failure could have an impact on the lives of the
humans or heavy loss in terms of cost or resources. The world has seen many failures due to
small faults in the software. For example, Ariane 5 failed due to small conversion/overflow error
in the software. Similarly small error in missile causes death of many soldiers in the war. Y2K
failure and other financial software failures are also examples of the software failure.
The failures that can affect the safety of human or that can have heavy losses or hardware
damages are very critical to be identified and removed. Hence, the safety critical software should
be adequately planned, assessed, monitored and tested.
The security of the data against accidental modifications or unauthorized access is a very
critical issue. The place where the software is deployed must also be secure and protected against
any damage or destruction. The data of the software should be protected from hackers, attackers
and viruses. If the software data becomes inaccurate, it affects the software behaviour and the
results obtained will not be correct.
The software quality professional must keep the management people aware of the security
concerns. There should also be provisions of recovery from a catastrophic failure.
The second level of quality attributes is known as quality criteria and is shown in Figure 8.6.
McCall software quality management consists of 11 quality factors which are mapped into 23
quality criteria. However, users and developers are concerned with the quality factors only. The
quality criteria provide insight into the quality attributes of the system.
The quality metrics can be used to capture the aspects of the quality criteria. The subjective
assessment of the quality criteria can be made by rating them on a scale from 0 (very bad) to
10 (very good). However, the use of such assessment is difficult as different people may rate the
same criterion differently. This makes correct quality assessment almost impossible.
The intermediate levels represent the quality that is expected from the software. The lowest
level represents the primitive metrics that will define and measure the quality of the model.
Boehm includes the characteristics of the hardware performance that are not present in McCall’s
model (Pfleeger, 2001). The human engineering aspect is sometimes very critical. The software
must be easy to access, use and understand no matter how good it is in performance. Boehm also
gives special focus on maintainability of the software.
Software Quality and Metrics 299
The major difference between ISO 9126 and McCall and Boehm quality models is that
ISO 9126 follows a strict hierarchy. Each characteristic is related to one attribute only.
and management of systems. At this level, everything is carried out on an ad hoc basis. The
success of a project depends on a competent manager and a good software project team.
The absence of sound management principles cannot even be covered by strong engineering
principles. The capability of software process is undisciplined at this level as the processes
are continuously changing or being modified as the software development progresses. The
performance completely depends upon individuals rather than on the organization’s abilities. As
the process totally depends upon the individual, it changes when the staff changes. Thus, time
and cost of development are unpredictable.
The past experience reports show that moving from level 1 to level 2 may take 3 to 5 years.
The CMM is becoming popular and many software organizations are aspiring to achieve CMM
level 5. The acceptability and pervasiveness of the CMM activities are helping the organizations
to produce a quality software.
The above definition covers a lot in itself. Software metrics are related to measures which, in
turn, involve numbers for quantification. These numbers are used to produce a better product
and improve its related process. Software metrics should be gathered from the beginning, when
the cost and effort of the product is to be estimated, to the monitoring of the reliability and
maintainability of the end product.
Class x is faulty or not faulty. Thus, there are two categories of faults—either they are present
or they are not present.
Similar to nominal scales, a metric having ordinal scale can be divided into categories or
classes; however, it involves ranking or ordering. In the ordinal scale, each category can be
compared with another in terms of “higher than” or “lower than” relationship. For example, fault
impact can be categorized as high, medium, and low. Numbers can be used to represent each
category shown as follows:
Ï1, high
Ô
fault impact = Ì 2, medium
Ô
Ó3, low
The metric scale provides higher precision permitting various arithmetic operations to be
performed. Interval, ratio and absolute scales are of metric type. In the interval scale, on any
part of the scale, the difference between two adjacent points is equal. The interval scale has an
arbitrary zero point. Thus, on an interval scale, it is not possible to express any value in multiple
of some other value on the scale. For example, a day with 100°F temperature cannot be said as
twice as hot as a day with 50°F temperature. The reason is that on Celsius scale, 100°F is 37.8
and 50°F is 10. Thus, this relationship can be expressed as:
F - 32
C = 5¥
9
Ratio scales give more precision since they have all advantages of other scales plus an absolute
zero point. For example, if weight of a person is 100 kg, then he/she is twice heavier compared
to a person with 50 kg weight. Absolute scale simply represents counts. For example, the
number of faults encountered during inspections can only be measured in one way by counting
the faults encountered. Table 8.7 summarizes the differences between measurement scales with
examples.
308 Object-Oriented Software Engineering
EXAMPLE 8.1 Consider the maintenance effort in terms of lines of source code added,
deleted, and changes during maintenance phase classified between 1 and 5, where 1 means very
high, 2 means high, 3 means medium, 4 means low and 5 means very low.
1. What is the measurement scale for this definition of maintenance effort?
2. Give an example to determine the criteria for estimating the maintenance effort levels for
a given class.
Solution
1. The measurement scale is ordinal since the variable maintenance effort is categorical
(consisting of classes) and involves ranking or ordering amongst categories.
2. For a given project, the following categorization may be used for maintenance effort:
Ï very high, SLOC > 10, 000
Ô
Ô high, 7000 £ SLOC < 10, 000
Ô
Maintenance effort = Ì medium, 5000 £ SLOC < 7000
Ô
Ô low, 1000 £ SLOC < 5000
ÔÓ very low, SLOC < 1000
Median gives the middle value in the data set which means half of the data points are below
the median value and half of the data points are above the median value. It is calculated as
(1/2) (n + 1)th value of the data set, where n is the number of data points in the data set.
The most frequently occurring value in the data set is denoted by mode. The concept has
significance for nominal data.
EXAMPLE 8.2 Consider the following data set consisting of SLOC for a given project:
107, 128, 186, 222, 322, 466, 657, 706, 790, 844, 1129, 1280, 1411, 1532, 1824, 1882, 3442
Calculate mean, median and mode for it.
Solution Mean of SLOC (taking the sum of all the numbers and dividing by total data points)
= 995.7647
Median of SLOC = 790
Since each value occurs only once in the data set, there is no mode for SLOC.
Software Quality and Metrics 311
Measures of Dispersion
Measures of dispersion include standard deviation, variance and quartiles. Measures of dispersion
tell us how the data is scattered or spread. Standard deviation calculates the distance of the
data point from the mean. If most of the data points are closer to the mean, then the standard
deviation of the variable is large. The standard deviation is calculated as given below:
2
 ( x - m)
sx =
N
Variance is a measure of variability and is the square of standard deviation.
The quartile divides the metric data into four equal parts. For calculating quartile, the data
is first arranged in ascending order. The 25% of the metric data is below the lower quartile
(25 percentile), 50% of the metric data is below the median value and 75% of the metric data is
below the upper quartile (75 percentile). Figure 8.11 shows the division of data set into four parts
by using quartiles.
1
Solution Lower quartile is the fifth value, i.e. (8 + 1)th = 322
2
Median = 790
Upper quartile is the thirteenth value = 1411.
312 Object-Oriented Software Engineering
The measures of central tendency such as mean, median and mode are all equal for normal
curves. The normal curve is like a bell-shaped curve and within three standard deviations of the
means, 96% of data occurs (Fenton and Pfleeger, 2004).
EXAMPLE 8.4 Consider the data sets given for three metric variables in Table 8.8. Determine
the normality of these variables.
Solution Figure 8.13 shows the bar charts to check the normality of the variables. The mean,
median and standard deviation of the variables are given in Table 8.9. The normality of the data
can also be checked by calculating mean and median. The mean, median and mode should be
the same for a normal distribution. In Table 8.9, we compare the values of mean and median.
The values of median are less than those of mean for variables fault count and branch count.
Thus, these variables are not normally distributed. However, the mean and median of cyclomatic
complexity do not differ by a larger value.
set; half of the values are less than this value and half of the values are greater than this value
(Figure 8.14).
EXAMPLE 8.5 Consider the data set given in Example 8.3. Construct box plots and identify
univariate outliers for all the variables in the data set.
316 Object-Oriented Software Engineering
Solution The box plots for LOC, fault count, cyclomatic complexity and branch count using
univariate analysis are shown in Figures 8.16–8.19.
The outliers should be analysed by the researchers to make a decision about their inclusion
or exclusion in the data analysis. There may be many reasons for an outlier: (i) error in the entry
of the data, (ii) some extra information that represents extraordinary or unusual event and (iii)
an extraordinary event that is unexplained by the researcher.
Outlier values may be present due to the combination of data values present across more than
one variable. These outliers are called multivariate outliers. Scatter plot is another visualization
method to detect outliers. In scatter plots, we simply represent graphically all the data points. The
scatter plot allows us to examine more than one metric variable at a given time. The univariate
outliers can also be determined by calculating the z-score value of the data points of the variable.
The data values exceeding ±2.5 are considered to be outliers (Hair et al., 2006).
318 Object-Oriented Software Engineering
EXAMPLE 8.6 Consider the data set given in Example 8.3. Identify bivariate outliers between
dependent variable fault count and other variables.
Solution The scatter plots are shown in Figures 8.20–8.22.
EXAMPLE 8.7 Consider the data set given in Example 8.3. Identify outliers by computing
z-score values.
Solution After computing the z-score values for all the given metrics, the following case
numbers are found to be influential (Table 8.10).
using various statistical and machine learning methods. The choice of the method for analysing
the relationship between independent and dependent variables depends upon the type of the
dependent variable (continuous or discrete).
If the dependent variable is continuous, then the widely known statistical method (linear
regression method) may be used, whereas if the dependent variable is of discrete type, then
logistic regression method may be used for analysing relationships.
The unit of measurement of volume is ‘bits’. A program can be implemented in various ways,
potential volume (V*) represents the program with minimal value. The program level is given as:
Level: L = V*/V
The difficulty is the inverse of program level:
Difficulty: D = 1/L
The potential volume of an algorithm is implemented as a procedure call and is given below:
V* = (2 + n 1*) log2(2 + n 2*)
The first term is 2 which represents two unique operators for the procedure call. The second term
n 2* represents the number of conceptually unique input and output parameters of a procedure.
The estimated program level and volume are given as:
2 n
L= ¥ 2
n1 N 2
1
Difficulty: D=
L
h1 N 2
=
2h2
V
Effort: E =
L
E
Program time: T =
b
b is normally equal to 18. The metrics proposed by Halstead can also be applied to object-
oriented software.
EXAMPLE 8.8 Consider the function to check the validity of a triangle given in Figure 8.23.
List out the operators and operands and also calculate the values of software science metrics.
Solution The list of operators and operands is given in Table 8.11.
(Contd.)
Software Quality and Metrics 323
Table 8.11 Tokens for the program given in Figure 8.23 (Contd.)
Operators Occurrences Operands Occurrences
else 1
return 1
; 4
, 2
() 7
h1 = 12 N1 = 33 h2 = 7 N2 = 19
h = h1 + h2
= 12 + 7 = 19
N = N1 + N 2
= 33 + 19 = 52
V = N ¥ log2 (n1 + n2 )
= 52 ¥ log2 19
= 52 ¥ 4.249 = 220.96 bits
N = h1 log2 n1 + h2 log2 n2
= 12 log2 12 + 7 log2 7
= 43.02 + 19.65 = 62.67
E 3599.44
T = = = 199.97 s
b 18
= 3.33 min
324 Object-Oriented Software Engineering
A low fan-out value is desirable since high fan-out values represent large amount of coupling
present in the system.
Defect Density
Defect density can be measured as the ratio of the number of defects encountered to the size of
the software. Size of the software is usually measured in terms of thousands of lines of code
(KLOC) and is given as:
Number of defects
Defect density =
KLOC
The number of defects counts the defects detected during testing or by using any verification
technique.
Defect rate can be measured as the number of defects encountered over a period of time
such as per year. The defect rate may be useful in predicting the cost and resources that will be
utilized in maintenance phase of software development. Another useful metric is defect density
during testing. It measures the defect density during the formal testing, i.e. after the source code
has been formally completed and added in the software library. If the value of defect density
metric during testing is high, then the tester should ask the following questions:
1. Is the software not well designed or developed?
2. Is the testing technique effective in detecting defects?
If the reason of higher defects is the first one, then the software should be tested thoroughly so
that higher defects are revealed. If the reason of higher defects is the second one, then the quality
perspective of the software is good.
Latent defects for a given phase is not known. Thus, they are estimated as the sum of defects
removed during a phase and defects detected later. The higher the value of the metric, the more
326 Object-Oriented Software Engineering
efficient and effective is the process followed in a particular phase. The ideal value of DRE is 1.
The DRE of a product can also be calculated by
DB
DRE =
DB + DA
where DB is defects encountered before software delivery and DA is defects encountered after
delivery.
The other measures that can be used to measure the usability of the system are as follows:
1. Time required to learn a system
2. Total increase in productivity by the use of the system
3. Response time
Conducting a survey based on a questionnaire is an effective means to measure the satisfaction
of the customer. The questionnaire should be developed by experience persons having technical
knowledge. The sample size should be sufficient enough to build the confidence level on
the survey results. The results rated on scale (for example, very satisfied, satisfied, neutral,
dissatisfied, very dissatisfied) may be used for measuring satisfaction level of the customer.
Software Quality and Metrics 327
The quality charts such as bar charts, scatter plots, line charts, etc. should be built to analyse
the satisfaction level of the customer. The customer satisfaction must be continuously monitored
over time.
On the basis of the above direct measures, we may design the following additional metrics so
that more useful information can be gained from the basic metrics:
1. Percentage of test cases executed
2. Percentage of test cases passed
3. Percentage of test cases failed
4. Total actual execution time/total estimated execution time
5. Average execution time of a test case
This definition also includes coupling based on inheritance. In 1994, Chidamber and Kemerer
defined coupling between objects (CBO). In their paper, they defined CBO as the count of the
number of other classes to which a class is coupled. The CBO definition given in 1994 includes
inheritance-based coupling. For example, consider Figure 8.25. Two variables of other classes
(class B and class C) are used in class A; hence, the value of CBO for class A is 2. Similarly, for
class B and class C, the value of CBO is zero.
Chidamber and Kemerer (1994) defined response for a class (RFC) metric as a set of methods
defined in a class and called by a class. It is given by RFC = | RS |, where RS, the response set
of the class, is given by:
RS = Mi all j{Rij}
where Mi = set of all methods in a class (total n) and Ri = {Rij} = set of methods called by Mi.
For example, in Figure 8.27, the RFC value for class A is 9 and the method for calculating it is
explained in the given example.
A system level metric, coupling factor, is also defined by Harrison et al. (1998). In 1997,
Briand et al. (1997) gave a suite of 18 metrics that measured different types of interaction
between classes. These metrics may be used to guide software developers about which type of
coupling affects maintenance cost and reduces reusability. Briand et al. (1997) observed that the
coupling between classes can be divided into different facets:
330 Object-Oriented Software Engineering
class A
{
B objB;
C objC;
public:
void A1(B obj1)
{
}
};
class B
{
public:
void B1()
{
A objA
A1();
}
};
class C
{
void A2(B::B1)
{
}
};
accessing a set of attributes Di (i = 1, ..., n). Let the number of methods that access each
datum be m(Di). The revised LCOM1 metric is given as:
n
1
N
 m (Di ) - m
i =1
LCOM1 =
1- m
Beiman and Kang (1995) defined two cohesion metrics: tight class cohesion (TCC) and loose
class cohesion (LCC). The TCC metric is defined as the percentage of pairs of directly connected
public methods of the class with common attribute usage. The LCC metric is the same as TCC,
except that it also considers indirectly connected methods. A method M1 is said to be indirectly
connected with method M3, if M1 is connected to method M2 and method M2 is connected
to method M3. Hence, indirectly connected methods represent transitive closure of directly
connected methods. Consider the source code of a queue class given in Figure 8.30 (Beiman
and Kang, 1995).
class queue
{
private:
int *a;
int rear;
int front;
int n;
public:
queue(int s)
{
n=s;
rear=0;
front=0;
a=new int[n];
}
int empty()
{
if(rear==0)
{
return 1;
}
else
{
return 0;
}
}
void insert(int);
int remove();
int getsize()
{
return n;
}
void display();
};
void queue::insert(int data)
{
if(rear==n)
{
cout<<“Queue overflow”;
}
else
{
a[rear++]=data;
}
}
int queue::remove()
{
int element,i;
if(empty())
{
cout<<“Queue underflow”;
getch();
}
else
{
element=a[front];
for(i=0;i<rear-1;i++)
{
a[i]=a[i+1];
}
rear--;
}
return element;
}
void queue::display()
{
int i;
for(i=0;i<rear;i++)
{
cout<<a[i]<<“ “;
}
getch();
}
Figure 8.31 shows the attribute usage of methods. The pair of public functions with common
attribute usage is given below:
{(empty, insert), (empty, remove), (empty, display), (getsize, insert), (insert, remove),
(insert, display), (remove, display)}
334 Object-Oriented Software Engineering
Thus,
7
TCC(Queue) = ¥ 100 = 70%
10
The methods empty and getsize are indirectly connected, since empty is connected to insert and
getsize is also connected to insert. Thus, by transitivity, empty is connected to getsize.
Thus,
10
LCC(Queue) = ¥ 100 = 100%
10
Lee et al. (1995) proposed information flow-based cohesion (ICH) metric. ICH for a class is
defined as the weighted sum of the number of invocations of other methods of the same class,
weighted by the number of parameters of the invoked method. In Figure 8.31, the method remove
invokes the method empty which does not consist of any arguments. Thus, ICH (Queue) = 1.
AID =
 Depth of each class
Total number of classes
In Figure 8.32, the depth of subclass D is 1.5 [(2 + 1)/2].
The AID of overall inheritance structure is: 0(A) + 1(B) + 0(C) + D(1.5) + E(1) + 0(F) = 3.5.
Finally, dividing by the total number of classes, we get 3.5/6 = 0.58.
Number of children (NOC) metric counts the number of immediate subclasses of a class
in a hierarchy. In Figure 8.32, the NOC value for class A is 1 and for class E it is 2. Lorenz
and Kidd developed number of parents (NOP) metric which counts the number of classes
that a class directly inherits (i.e. multiple inheritance) and number of descendants (NOD) as
the number of subclasses of a class (both directly and indirectly). Number of ancestors (NOA)
given by Tegarden and Sheetz (1992) counts the number of base classes of a class (both directly
and indirectly). Hence, in Figure 8.32, NOA(D) = 3 (A, B, C), NOP(D) = 2 (B, C) and NOD(A)
= 2 (B, D).
Lorenz and Kidd (1994) gave three measures: number of methods overridden (NMO),
number of methods added (NMA) and number of methods inherited (NMI). When a method
in a subclass has the same name and type (signature) as in the superclass, then the method in
the superclass is said to be overridden by the method in the subclass. NMA counts the number
of new methods (neither overridden nor inherited) added in a class. NMI counts the number of
methods a class inherits from its superclasses. Finally, Lorenz and Kidd use NMO, NMA and
NMI metrics to calculate specialization index (SIX) as given below:
NMO ¥ DIT
SIX =
NMO + NMA + NMI
Consider the source code given in Figure 8.33. The class student overrides two methods of class
person—readperson() and displayperson(). Thus, the value of the NMO metric for class student
is two. One new method is added in this class (getaverage). Hence, the value of NMA metric is 1.
Similarly, for class GradStudent, the value of NMO is 2, NMA is 1 and NMI is 1
(getaverage( )). The value of SIX for class GradStudent is given by
2¥2 4
SIX = = =1
2 +1+1 4
The maximum number of levels in the inheritance hierarchy which is below the class is measured
through class to leaf depth (CLD). The value of CLD for class person is 2.
class Person {
protected:
char name[25];
int age;
public:
void readperson();
void displayperson();
};
class Student extends Person{
protected:
roll _ no[10];
float average;
public:
void readstudent();
void displaystudent();
float getaverage();
};
class GradStudent extends Student{
private:
char subject[25];
char working[25];
public:
void readit();
void displaysubject();
void workstatus();
};
Consider Figure 8.33, the value of U is 2/3. Another metric is specialization ratio (S), which is
given by
Number of subclasses
S=
Number of superclasses
void function1(){
.........}
template<class T>
void function2(T &x, T &y){
.........}
void function3(){
........}
Figure 8.34 Source code for calculating metric FTF.
class A{
.....};
template<class T, int size>
class B{
T arr[size];
....};
Figure 8.35 Source code for calculating metric CTF.
where M1, ..., Mn are methods defined in class K1 and C1, ..., Cn are the complexity of the methods.
The number of attributes (NOA), given by Lorenz and Kidd, is defined as the sum of the
number of instance variables and number of class variables. Number of methods (NOM) given
by Li and Henry (1993) is defined as the number of local methods defined in a class. They also
gave two additional size metrics SIZE1 and SIZE2 besides the LOC metric given as:
SIZE1 = number of semicolons in a class
SIZE2 = NOA + NOM
2. Li and Henry (1993) investigated Chidamber and Kemerer metrics and proposed a suite
of five metrics. These metrics are summarized in Table 8.13.
Software Quality and Metrics 339
Table 8.13 Li and Henry metric suite
Metric Definition Construct being measured
DAC Data abstraction coupling Coupling
MPC Message passing coupling
NOM Number of methods Size
SIZE1 Number of semicolons
SIZE2 Number of attributes + NOM
3. Beiman and Kang (1995) proposed two cohesion metrics LCC and TCC.
4. Lorenz and Kidd (1994) proposed a suite of 11 metrics. These metrics address size,
coupling, inheritance, etc. and are summarized in Table 8.14.
5. Briand et al. (1997) proposed a suite of 18 coupling metrics. These metrics are
summarized in Table 8.15.
8. The system level polymorphism metrics are measured by Benlarbi and Melo (1999). These
metrics are used to measure static and dynamic polymorphism and are summarized in
Table 8.17.
9. Yap and Henderson-Sellers (1993) have proposed a suite of metrics to measure cohesion
and reuse in object-oriented systems.
10. Aggarwal et al. (2006) have proposed a set of two metrics (FTF and CTF) to measure
reuse in object-oriented systems.
Review Questions
1. What is software quality? Explain the various software quality attributes.
2. Define the following software quality attributes:
(a) Functionality
(b) Reliability
(c) Maintainability
(d) Adaptability
3. Establish the relationship between reliability and maintainability. How does one affect
the effectiveness of the other?
Software Quality and Metrics 341
4. Describe the elements of a quality system. Why should customer’s satisfaction be the
prime concern for developers?
5. Design the table of associations between elements of a quality system and life cycle
phases. Which life cycle phases require all elements of a quality system and why?
6. Explain the McCall’s software quality model. Discuss the significance and importance
of product quality factors.
7. Establish the relationship between quality factors and quality criteria in McCall’s
software quality model.
8. What is defect management and trend analysis of a quality system? Explain with the
help of a format for software defect report.
9. Define the following terms:
(a) Configuration management
(b) Risk management activities
(c) Reviews and audits
(d) Standards, processes and metrics
10. Explain the Boehm’s software quality model with software quality attributes in the form
of a hierarchy.
11. What is ISO 9000? List the processes which can be improved and better maintained by
the implementation of ISO 9000.
12. Discuss ISO 9126. How is it different from ISO 9000? Highlight a few characteristics
which are part of this model.
13. What is CMM? How does it encourage the continuous improvement of the software
processes?
14. Explain the various KPAs at different maturity levels. List some of the difficulties of
achieving CMM level 5.
15. Compare CMM and ISO 9126 models. Which is more popular and why?
16. What are software metrics? Discuss their areas of applications.
17. What are the various categories of software metrics? Explain each category with the
help of examples.
18. Define nominal scale and ordinal scale in the measurements and also discuss both the
concepts with examples.
19. Explain the role and significance of Weyuker’s properties in software metrics.
20. Describe the measures of central tendency. Discuss the concepts with examples.
21. Consider the following data set consisting of lines of source code for a given project:
100, 150, 156, 187, 206, 209, 235, 270, 275, 280, 305, 309, 351, 359, 375, 400,406, 410,
450, 475, 500
Calculate mean, median and mode.
342 Object-Oriented Software Engineering
22. Describe the measures of dispersion. Explain the concepts with examples.
23. Consider the data set consisting of lines of source code given in Question 21. Calculate
the standard deviation, variance and quartile.
24. Consider the following data sets given for three metric variables. Determine the
normality of these variables.
25. What is outlier analysis? Discuss its importance in data analysis. Explain univariate,
bivariate and multivariate.
26. Consider the data set given in Question 24. Construct box plots and identify univariate
outliers for all variables in the data set.
27. Consider the data set given in Question 24. Identify bivariate outliers between the
dependent variable fault count and other variables.
28. Explain the various size estimation metrics. Which one is most popular and why?
29. Explain Halstead’s software science metrics. How can we estimate program length?
Highlight some advantages of these metrics.
30. Define the role of fan-in and fan-out in information flow metrics.
31. What are the various measures of software quality? Discuss any one with examples.
32. What are the various usability metrics? What is the role of customer satisfaction?
33. Define the following testing metrics:
(a) Statement coverage metric
(b) Branch coverage metric
(c) Condition and path coverage metrics
(d) Fault coverage metric
34. What is software coupling? Explain some coupling metrics with examples.
35. What is software cohesion? Explain some cohesion metrics with examples.
36. How do we measure inheritance? Explain inheritance metrics with examples.
Software Quality and Metrics 343
37. Define the following inheritance metrics:
(a) DIT
(b) AID
(c) NOC
(d) NOP
(e) NOD
(f) NOA
38. Define the following:
(a) Reuse ratio
(b) Specialization ratio
(c) FTF and CTF
39. Define the following size metrics:
(a) Weighted methods per class (WMC)
(b) Number of attributes (NOA)
(c) Number of methods (NOM)
40. Explain the metric suite of Chidamber and Kemerer. Highlight the strengths and
weaknesses of this metric suite.
DB + DA DB + DA
(c) (d)
DB DA
Further Reading
Hortch presents full account of the element of software quality system:
Horch, John W., Practical Guide to Software Quality Management. Norwood, MA: Artech
House, 2003.
An in-depth study of 18 different categories of software complexity metrics was provided by
Zuse, where he tried to give the basic definition of metrics in each category:
Zuse, H., Software Complexity: Measures and Methods. Berlin: Walter De Gryter, 1990.
Fenton and Pfleeger’s book is a classic and useful reference, and it gives detailed discussion on
measurement and key definition of metrics:
Fenton, N. and Pfleeger, S., Software Metrics: A Rigorous & Practical Approach. Boston: PWS
Publishing Company, 1997.
A detailed description on software reliability and contributions from many of the leading
researchers may be found in Lyu’s book:
Lyu, M., Handbook of Software Reliability Engineering. Los Angeles: IEEE Computer Press,
1996.
Aggarwal presents a good overview of software reliability models. Musa et al. provides a detailed
description particularly on software reliability models:
Aggarwal, K.K., Reliability Engineering. New Delhi: Kluwer, 1993.
Musa, J.D., Lannino, A. and Okumoto, K., Software Reliability: Measurement, Prediction and
Applications. New York: McGraw Hill, 1987.
The first significant OO design metrics suite was proposed by Chidamber and Kemerer in 1991.
Then came another paper by Chidamber and Kemerer defining and validating metrics suite
for OO design in 1994. This metric suite has received the widest attention in empirical
studies:
Chidamber, S., and Kemerer, C., A metrics suite for object-oriented design. IEEE Transactions
on Software Engineering, 20(6): 476–493, 1994.
There are several books on research methodology and statistics with their applications:
Kothari, C.R., Research Methodology: Methods and Techniques. New Delhi: New Age
International Limited, 2004.
Hopkins, W.G., A new view of statistics. Sport Science, 2003.
Software Quality and Metrics 347
The details on outlier analysis can be obtained from:
Barnett, V. and Price, T., Outliers in Statistical Data. Chichester: John Wiley & Sons, 1995.
For a detailed account of the statistics needed for model prediction using logistic regression
(notably how to compute maximum likelihood estimates, R2, significance values), see the
following textbook and research paper:
Hosmer, D., and Lemeshow, S., Applied Logistic Regression. New York: John Wiley & Sons,
1989.
Basili, V., Briand, L., and Melo, W., “A validation of object-oriented design metrics as quality
indicators. IEEE Transactions on Software Engineering, 22(10): 751–761, 1996.
Detailed description on object-oriented metrics can be obtained from:
Lorenz, M. and Kidd, J., Object-Oriented Software Metrics. Englewood Cliff, NJ: Prentice-Hall,
1994.
Henderson-Sellers, B., Object-oriented Metrics: Measures of Complexity. Englewood Cliff, NJ:
Prentice-Hall, 1996.
Various object-oriented metrics are explained with real-life examples in:
Aggarwal, K.K., Singh, Y., Kaur, A. and Malhotra, R., Empirical study of object-oriented
metrics. Journal of Object Technology, 5(8): 149–173, 2006.
Relevant publications on object-oriented metrics can be obtained from:
http://www.sbu.ac.uk/~csse/publications/OOMetrics.html
Complete bibliography on object-oriented metrics can be obtained from:
Object-Oriented Metrics: An Annotated Bibliography, http://dec.bournemouth.ac.uk/ESERG/
bibliography.html
9
Software Testing
Software testing is a very important, challenging and essential activity. It starts along with the
design of SRS document and ends at the delivery of software product to the customer. It consumes
significant effort and maximum time of software development life cycle (without including the
maintenance phase). The significant effort may be from one third to one half of the total effort
expended till the delivery of the software product. We cannot imagine to deliver a software
product without adequate testing. The existing testing techniques help us to do adequate testing.
However, adequate testing has different meaning to different software testers.
348
Software Testing 349
This definition motivates us to select those inputs which have higher probability of finding
faults, although the definition is also not complete because it focuses only on the execution of
the program. Nowadays, attention is also given to the activities like reviewing the documents
and programs. Reviewing the documents (like SRS and SDD) helps us to find a good number
of faults in the early phases of software development. Hence, testing is divided into two parts:
verification and validation. Therefore, the most appropriate definition of software testing is:
Software testing is the process of verifying the outcomes of every phase of software development
and validating the program by executing it with the intention of finding faults.
In the initial days of programming, testing was primarily validation oriented but nowadays both
are equally important and carried out in most of the software organizations.
9.1.1 Verification
Software verification is also known as static testing where testing activities are carried out
without executing the program. It may include inspections, walkthroughs and reviews where
documents and programs are reviewed with the purpose of finding faults. Hence, verification
is the process of reviewing (rechecking) documents and program with the intention of finding
faults. As per the IEEE (2001):
The verification is the process of evaluating the system or component to determine whether the
products of a given development phase satisfy the conditions imposed at the start of that phase.
9.1.2 Validation
Software validation is also known as dynamic testing where the program is executed with given
input(s). Hence, validation involves execution of the program and usually exposes symptoms of
errors. As per the IEEE (2001):
The validation is the process of evaluating a system or component during or at the end of
development process to determine whether it satisfies the specified requirements.
Validation activities are carried out with the execution of the program. We experience failures
and reasons of such failures are identified.
Software testing includes both verification and validation. Both are important and
complementary to each other. Effective verification activities find a good number of faults in
the early phases of software development. Removing such faults will definitely provide better
foundations for the implementation/construction phase. Validation activities are possible only
after the implementation of module/program, but verification activities are possible in every
phase of software development.
the software professionals are convinced about the importance and usefulness of verification
techniques. They also believe that a good quality software product can be produced only after the
effective implementation of verification techniques. Many verification techniques are commonly
used in practice and some of them are discussed in the following subsections.
9.2.2 Walkthroughs
Walkthrough is a group activity for reviewing the documents and programs. It is a more formal
and systematic technique than per reviews. A group of two to seven persons is constituted for
the purpose of reviewing. The author of the document presents the document to the group during
walkthroughs conducted in a conference room. The author may use any display mechanism (like
whiteboard, projector) for presentation. Participants are not expected to prepare anything prior
to such a meeting. Only the presenter who happens to be the author of the document prepares
for the walkthrough. Documents and/or programs are distributed to every participant and the
author presents the contents to all to make them understand. All participants are free to ask
questions and write their observations on any display mechanism in such a way that everyone
can see it. The observations are discussed thoroughly amongst the participants and changes
are suggested accordingly. The author prepares a detailed report as per suggested changes. The
report is studied, changes are approved and documents/programs are modified.
The limitations of such a technique are the non-preparation of participants prior to meeting
and presentation of documents by their author(s). The author(s) may unnecessarily highlight
some areas and hide a few critical areas. Participants may also not be able to ask critical and
penetrating questions. Walkthroughs may create awareness amongst participants and may also
find a few important faults. This technique is more expensive but systematic than peer reviews
and applicable to any size of software project.
9.2.3 Inspections
This technique is more formal, systematic and effective. There are many names for this
technique like formal reviews, formal technical reviews and inspections. The most popular
Software Testing 351
name is inspection and is different from peer reviews and walkthroughs. A group of three to
six persons is constituted. The author of the document is not the presenter. An independent
presenter is appointed for this specific purpose who prepares and understands the document.
This preparation provides a second eye on the document(s) prior to meeting. The documents(s)
is/are distributed to every participant in advance to give sufficient time for preparation. Rules
of the meeting are prepared and circulated to all participants in advance to make them familiar
with the framework of the meeting. The group is headed by an impartial moderator who should
be a senior person to conduct the meetings smoothly. A recorder is also engaged to record the
proceedings of the meetings.
The presenter presents the document(s) in the meeting and makes everyone comfortable
with the document(s). Every participant is encouraged to participate in the deliberations as
per modified rules. Everyone gets time to express his/her views, opinions about quality of
document(s), potential faults and critical areas. The moderator chairs the meeting, enforces the
discipline as per prescribed rules and respects views of every participant. Important observations
are displayed in a way that is visible to every participant. The idea is to consider everyone’s
views and not to criticize them. Many times, a checklist is used to review the document. After
the meeting, the moderator along with the recorder prepares a report and circulates it to all
participants. Participants may discuss the report with the moderator and suggest changes. A
final report is prepared after incorporating changes. The changes should be approved by the
moderator. Most of the organizations use inspections as a verification technique and outcomes
are very good. Many faults are generally identified in the early phases of software development.
This is a popular, useful and systematic technique and is effective for every type of document
and program. The comparison of all the three techniques is given in Table 9.1.
Verification is always more useful than validation due to its applicability in early phases
of software development. It finds those faults which may not be detected by any validation
technique. Verification techniques are becoming popular and more attention is given to such
techniques from the beginning of the software development.
352 Object-Oriented Software Engineering
Part II
(Contd.)
Software Testing 353
Table 9.2 Checklist for a good quality software (Contd.)
S. No. Description Yes/No/NA Comments
12. Do you want to delete any field in any form?
13. Do you want to add/delete any validity check?
14. Is readability of the document satisfactory?
15. Are non-functional requirements specified?
Actors, use cases and use case description
16. Are all the actors identified?
17. Are all the use cases determined?
18. Does the name of the use case represent the function it is
required to perform?
19. Are all the actors included in the use case description of each
use case?
20. Are you ready to accept identified use cases and their
descriptions?
21. Does the use case description include precondition?
22. Does the use case description include postcondition?
23. Is the basic flow in the use case complete?
24. Are all the alternative flows of the use case stated?
25. Are related use cases stated?
Characteristics of requirements
26. Are all requirements feasible?
27. Are requirements non-feasible due to technical problems?
28. Are requirements non-feasible due to inadequate resources?
29. Are a few requirements difficult to implement?
30. Are all requirements conveying only one meaning?
31. Are there conflicts amongst requirements?
32. Are all functional and non-functional requirement defined?
33. Are all use cases clearly understandable?
34. Are all forms available with adequate validity checks?
35. Are all requirements specified at a consistent level of detail?
36. Is consistency maintained throughout the document?
37. Are there any conflicts amongst requirements?
38. Are all defined requirements verifiable?
39. Are all stated requirements understandable?
40. Are redundant requirements identified?
41. Do you want to add a requirement?
42. Are all stated requirements written in a simple language?
(Contd.)
354 Object-Oriented Software Engineering
Part II
Part II
(Contd.)
356 Object-Oriented Software Engineering
Every dot of the input domain represents input(s) and every dot of the output domain
represents output(s). Every dot of the input domain has a corresponding dot in the output
domain. We consider valid and invalid inputs for the purpose of program execution and note the
behaviour in terms of observed outputs. Functional testing techniques provide ways to design
effective test cases to find errors in the program.
The technique selects only five values instead of 900 values to test the program. These
values of a are 100, 101, 550, 999, 1000 which cover the boundary portions of the input value
except one nominal value (say 550). The nominal value represents those values which are neither
on the boundary nor close to boundary. The number of test cases designed by this technique
is 4n + 1, where n is the number of input values. The test cases generated for the ‘square root’
program are shown in Table 9.5.
We consider a program ‘subtraction’ with two input values a and b and the output is the
subtraction of a and b. The ranges of input values are shown as:
100 a 1000
200 b 1200
The selected values for a and b are given as:
a = (100, 101, 550, 999, 1000)
b = (200, 201, 700, 1199, 1200)
358 Object-Oriented Software Engineering
Both inputs (a and b) are required for the execution of the program. The input domain is
shown in Figure 9.3 where any point within the rectangle is a legitimate input of the program.
The test cases are generated on the basis of ‘single fault’ assumption theory of reliability.
This theory assumes that failures are rarely the result of simultaneous occurrence of two (or
more) faults. Generally one fault is responsible for a failure. The implication of this theory is
that we select one input for any of the defined states (minimum, just above minimum, just below
maximum, maximum, nominal) and other input(s) as nominal values.
The test cases are 4n + 1 (i.e. 8 + 1 = 9) which are given in Table 9.6. The input values are
also shown graphically in Figure 9.3.
EXAMPLE 9.1 Consider a program to multiply and divide two numbers. The inputs may be
two valid integers (say a and b) in the range of [0, 100]. Generate boundary value analysis test
cases.
Solution Boundary value analysis test cases are given in Table 9.7.
Software Testing 359
Table 9.7 Boundary value analysis test cases for Example 9.1
Test case a b Expected output
1 0 50 0 0
2 1 50 50 0
3 50 50 2500 1
4 99 50 4950 1
5 100 50 5000 2
6 50 0 0 Divide by zero error
7 50 1 50 50
8 50 99 4950 0
9 50 100 5000 0
EXAMPLE 9.2 Consider a program which takes a date as an input and checks whether it is
a valid date or not. Its input is a triple of day, month and year with the values in the following
ranges:
1 month 12
1 day 31
2000 year 2070
Generate boundary value analysis test cases.
Solution Boundary value analysis test cases are given in Table 9.8.
Table 9.8 Boundary value test cases for program determining validity of date
Test case Month Day Year Expected output
1 1 15 2035 Valid date (1/15/2035)
2 2 15 2035 Valid date (2/15/2035)
3 6 15 2035 Valid date (6/15/2035)
4 11 15 2035 Valid date (11/15/2035)
5 12 15 2035 Valid date (12/15/2035)
6 6 1 2035 Valid date (6/1/2035)
7 6 2 2035 Valid date (6/2/2035)
8 6 30 2035 Valid date (6/30/2035)
9 6 31 2035 Invalid date
10 6 15 2000 Valid date (6/15/2000)
11 6 15 2001 Valid date (6/15/2001)
12 6 15 2069 Valid date (6/15/2069)
13 6 15 2070 Valid date (6/15/2070)
There are three extensions of boundary value analysis technique and are given below:
(i) Robustness testing
Two additional states ‘just below minimum’ and ‘just above maximum’ are added to see the
behaviour of the program with invalid input values. Invalid inputs are equally important and
may make the program fail when such inputs are given.
360 Object-Oriented Software Engineering
There are seven states in robustness testing and are given as:
1. Just below minimum (minimum–)
2. Minimum
3. Just above minimum (minimum+)
4. Nominal (average value)
5. Just below maximum (maximum–)
6. Maximum
7. Just above maximum (maximum+)
The total number of test cases generated for robustness testing is 6n + 1, where n is the number
of input values. Test cases for ‘subtraction’ program using robustness testing are 13 as given in
Table 9.9.
The input domain has four test cases which are outside; the other test cases lie in the
legitimate input domain as shown in Figure 9.4.
Figure 9.4 Input domain of ‘subtraction’ program for robustness test cases.
Software Testing 361
(ii) Worst case testing
This is another form of boundary value analysis where the single fault assumption theory of
reliability is rejected. Hence, a failure may also be the result of the occurrence of more than one
fault simultaneously. The result of this rejection is that one, two or all input values may have one
of the following states:
Minimum
Minimum+
Nominal (average value)
Maximum–
Maximum
In the worst case testing, the restriction of one input value at the above-mentioned states
and other input values nominal is removed. The implication is that the number of test cases
will increase from 4n + 1 test cases to 5n test cases, where n is the number of input values. The
‘subtraction’ program will have 52 = 25 test cases which are shown in Table 9.10.
The inputs given in Table 9.10 are graphically represented in Figure 9.5.
In the worst case testing, we select more number of test cases for completeness and
thoroughness. This is a more effort and time-consuming technique.
(iii) Robust worst case testing
Two more states are added to check the behaviour of the program with invalid inputs. These
two states are ‘just below minimum’ and ‘just above maximum’. The total number of test cases
generated by this technique is 7n. The subtraction program has 72 = 49 test cases which are given
in Table 9.11.
(Contd.)
Software Testing 363
Table 9.11 Robust worst test cases for ‘subtraction’ program (Contd.)
Boundary value analysis is a useful technique and may generate effective test cases. There
is a restriction that input values should be independent. It is not applicable for Boolean variables
because of only two available states—true and false. The technique is also easy to understand
and implement for any size of program.
EXAMPLE 9.3 Consider a program to multiply and divide two numbers as explained in
Example 9.1. Design the robust test cases and worst test cases for this program.
Solution Robust test cases are given in Table 9.12.
Table 9.12 Robust test cases for a program to multiply and divide two numbers
Test case a b Expected output
1 –1 50 Input values are out of range
2 0 50 0 0
3 1 50 50 0
4 50 50 2500 1
5 99 50 4950 1
6 100 50 5000 2
7 101 50 Input values are out of range
8 50 –1 Input values are out of range
9 50 0 0 Divide by zero error
10 50 1 50 50
11 50 99 4950 0
12 50 100 5000 0
13 50 101 Input values are out of range
Software Testing 365
Worst test cases are given in Table 9.13.
Table 9.13 Worst test cases for a program to multiply and divide two numbers
Test case a b Expected output
Multiply Divide
1 0 0 0 Undefined*
2 0 1 0 0
3 0 50 0 0
4 0 99 0 0
5 0 100 0 0
6 1 0 0 Divide by zero error
7 1 1 1 1
8 1 50 50 1
9 1 99 99 1
10 1 100 100 1
11 50 0 0 Divide by zero error
12 50 1 50 50
13 50 50 2500 1
14 50 99 4950 0
15 50 100 5000 0
16 99 0 0 Divide by zero error
17 99 1 99 99
18 99 50 4950 1
19 99 99 9801 1
20 99 100 9900 0
21 100 0 0 Divide by zero error
22 100 1 100 100
23 100 50 5000 2
24 100 99 9900 1
25 100 100 10,000 1
EXAMPLE 9.4 Consider the program for the determination of validity of the date as explained
in Example 9.2. Design the robust and worst test cases for this program.
Solution Robust test cases and worst test cases are given in Tables 9.14 and 9.15, respectively.
366 Object-Oriented Software Engineering
Table 9.14 Robust test cases for program for determining the validity of the date
Test case Month Day Year Expected output
1 0 15 2035 Invalid date
2 1 15 2035 Valid date (1/15/2035)
3 2 15 2035 Valid date (2/15/2035)
4 6 15 2035 Valid date (6/15/2035)
5 11 15 2035 Valid date (11/15/2035)
6 12 15 2035 Valid date (12/15/2035)
7 13 15 2035 Invalid date
8 6 0 2035 Invalid date
9 6 1 2035 Valid date (6/1/2035)
10 6 2 2035 Valid date (6/2/2035)
11 6 30 2035 Valid date (6/30/2035)
12 6 31 2035 Invalid date
13 6 32 2035 Invalid date
14 6 15 1999 Invalid date (out of range)
15 6 15 2000 Valid date (6/15/2000)
16 6 15 2001 Valid date (6/15/2001)
17 6 15 2069 Valid date (6/15/2069)
18 6 15 2070 Valid date (6/15/2070)
19 6 15 2071 Invalid date (out of range)
Table 9.15 Worst test cases for the program determining the validity of the date
Test case Month Day Year Expected output
1 1 1 2000 Valid date (1/1/2000)
2 1 1 2001 Valid date (1/1/2001)
3 1 1 2035 Valid date (1/1/2035)
4 1 1 2069 Valid date (1/1/2069)
5 1 1 2070 Valid date (1/1/2070)
6 1 2 2000 Valid date (1/2/2000)
7 1 2 2001 Valid date (1/2/2001)
8 1 2 2035 Valid date (1/2/2035)
9 1 2 2069 Valid date (1/2/2069)
10 1 2 2070 Valid date (1/2/2070)
11 1 15 2000 Valid date (1/15/2000)
12 1 15 2001 Valid date (1/15/2001)
13 1 15 2035 Valid date (1/15/2035)
14 1 15 2069 Valid date (1/15/2069)
(Contd.)
Software Testing 367
Table 9.15 Worst test cases for the program determining the validity of the date (Contd.)
Table 9.15 Worst test cases for the program determining the validity of the date (Contd.)
Table 9.16 Test cases of ‘square root’ program for input domain
Test case Input a Expected output
I1 500 22.36
I2 10 Invalid input
I3 1100 Invalid input
The output domain is also partitioned to generate equivalence classes. We generate the
following output domain equivalence classes:
O1 = {Square root of input value a}
O2 = {Invalid value}
Software Testing 371
The test cases for the output domain are given in Table 9.17. Some of the input and output
domain test cases may be the same.
Table 9.17 Test cases of ‘square root’ program for output domain
Test case Input a Expected output
O1 500 22.36
O2 1100 Invalid input
We consider the ‘subtraction’ program which takes two inputs a (range 100–1000) and b
(range 200–1200) and performs the subtraction of these two input values. On the basis of the
input domain, we generate the following equivalence classes:
(i) I1 = {100 a 1000 and 200 b 1200} (Both a and b are valid values)
(ii) I2 = {100 a 1000 and b < 200} (a is valid and b is invalid)
(iii) I3 = {100 a 1000 and b > 1200} (a is valid and b is invalid)
(iv) I4 = {a < 100 and 200 b 1200} (a is invalid and b is valid)
(v) I5 = {a > 1000 and 200 b 1200} (a is invalid and b is valid)
(vi) I6 = {a < 100 and b < 200} (Both inputs are invalid)
(vii) I7 = {a < 100 and b > 1200} (Both inputs are invalid)
(viii) I8 = {a > 1000 and b < 200} (Both inputs are invalid)
(ix) I9 = {a > 1000 and b > 1200} (Both inputs are invalid)
The input domain test cases are given in Table 9.18.
The test cases for the output domain are given in Table 9.19.
We have designed only one equivalence class for the valid input domain in both of the
above discussed examples. We could not partition the valid input domain due to simplicity of
the problem. However, programs are more complex and logic oriented. We may design more
valid input domain equivalence classes on the basis of logic and relationship. The design of
equivalence classes is subjective and two designers may design different classes. The objective
is to cover every functionality of the program which may further cover maximum portion of
the source code during testing. This technique is applicable at unit, integration system and
acceptance testing levels. This is a very effective technique if equivalence classes are designed
correctly and also reduces the number of test cases significantly.
EXAMPLE 9.5 Consider a program to multiply and divide two numbers. The inputs may be
two valid integers (say a and b) in the range of [0, 100]. Develop test cases using equivalence
class testing.
Solution The test cases are generated for output domain given in Table 9.20:
EXAMPLE 9.6 Consider the program for determining whether the date is valid or not. Identify
the equivalence class test cases for output and input domains.
Solution Output domain equivalence classes are:
O1 = {< Day, Month, Year > : Valid}
O2 = {< Day, Month, Year > : Invalid date if any of the inputs is invalid}
O3 = {< Day, Month, Year > : Input is out of range if any of the inputs is out of range}
The output domain test cases are given in Table 9.22.
I35 = {M4 and D2 and Y2} (Month is invalid, Day is valid and Year is valid)
I36 = {M5 and D2 and Y2} (Month is invalid, Day is valid and Year is valid)
I37 = {M4 and D3 and Y2} (Month is invalid, Day is valid and Year is valid)
I38 = {M5 and D3 and Y2} (Month is invalid, Day is valid and Year is valid)
I39 = {M4 and D4 and Y2} (Month is invalid, Day is valid and Year is valid)
I40 = {M5 and D4 and Y2} (Month is invalid, Day is valid and Year is valid)
I41 = {M1 and D5 and Y1} (Month is valid, Day is invalid and Year is valid)
I42 = {M1 and D6 and Y1} (Month is valid, Day is invalid and Year is valid)
I43 = {M2 and D5 and Y1} (Month is valid, Day is invalid and Year is valid)
I44 = {M2 and D6 and Y1} (Month is valid, Day is invalid and Year is valid)
I45 = {M3 and D5 and Y1} (Month is valid, Day is invalid and Year is valid)
I46 = {M3 and D6 and Y1} (Month is valid, Day is invalid and Year is valid)
I47 = {M1 and D5 and Y2} (Month is valid, Day is invalid and Year is valid)
I48 = {M1 and D6 and Y2} (Month is valid, Day is invalid and Year is valid)
I49 = {M2 and D5 and Y2} (Month is valid, Day is invalid and Year is valid)
I50 = {M2 and D6 and Y2} (Month is valid, Day is invalid and Year is valid)
I51 = {M3 and D5 and Y2} (Month is valid, Day is invalid and Year is valid)
I52 = {M3 and D6 and Y2} (Month is valid, Day is invalid and Year is valid)
I53 = {M1 and D1 and Y3} (Month is valid, Day is valid and Year is invalid)
I54 = {M1 and D1 and Y4} (Month is valid, Day is valid and Year is invalid)
I55 = {M2 and D1 and Y3} (Month is valid, Day is valid and Year is invalid)
I56 = {M2 and D1 and Y4} (Month is valid, Day is valid and Year is invalid)
I57 = {M3 and D1 and Y3} (Month is valid, Day is valid and Year is invalid)
I58 = {M3 and D1 and Y4} (Month is valid, Day is valid and Year is invalid)
I59 = {M1 and D2 and Y3} (Month is valid, Day is valid and Year is invalid)
I60 = {M1 and D2 and Y4} (Month is valid, Day is valid and Year is invalid)
I61 = {M2 and D2 and Y3} (Month is valid, Day is valid and Year is invalid)
I62 = {M2 and D2 and Y4} (Month is valid, Day is valid and Year is invalid)
I63 = {M3 and D2 and Y3} (Month is valid, Day is valid and Year is invalid)
I64 = {M3 and D2 and Y4} (Month is valid, Day is valid and Year is invalid)
I65 = {M1 and D3 and Y3} (Month is valid, Day is valid and Year is invalid)
I66 = {M1 and D3 and Y3} (Month is valid, Day is valid and Year is invalid)
I67 = {M2 and D3 and Y3} (Month is valid, Day is valid and Year is invalid)
I68 = {M2 and D3 and Y4} (Month is valid, Day is valid and Year is invalid)
I69 = {M3 and D3 and Y3} (Month is valid, Day is valid and Year is invalid)
I70 = {M3 and D3 and Y4} (Month is valid, Day is valid and Year is invalid)
I71 = {M1 and D4 and Y3} (Month is valid, Day is valid and Year is invalid)
I72 = {M1 and D4 and Y4} (Month is valid, Day is valid and Year is invalid)
I73 = {M2 and D4 and Y3} (Month is valid, Day is valid and Year is invalid)
I74 = {M2 and D4 and Y4} (Month is valid, Day is valid and Year is invalid)
376 Object-Oriented Software Engineering
I75 = {M3 and D4 and Y3} (Month is valid, Day is valid and Year is invalid)
I76 = {M3 and D4 and Y4} (Month is valid, Day is valid and Year is invalid)
I77 = {M4 and D5 and Y1} (Month is invalid, Day is invalid and Year is valid)
I78 = {M4 and D5 and Y2} (Month is invalid, Day is invalid and Year is valid)
I79 = {M4 and D6 and Y1} (Month is invalid, Day is invalid and Year is valid)
I80 = {M4 and D6 and Y2} (Month is invalid, Day is invalid and Year is valid)
I81 = {M5 and D5 and Y1} (Month is invalid, Day is invalid and Year is valid)
I82 = {M5 and D5 and Y2} (Month is invalid, Day is invalid and Year is valid)
I83 = {M5 and D6 and Y1} (Month is invalid, Day is invalid and Year is valid)
I84 = {M5 and D6 and Y2} (Month is invalid, Day is invalid and Year is valid)
I85 = {M4 and D1 and Y3} (Month is invalid, Day is valid and Year is invalid)
I86 = {M4 and D1 and Y4} (Month is invalid, Day is valid and Year is invalid)
I87 = {M4 and D2 and Y3} (Month is invalid, Day is valid and Year is invalid)
I88 = {M4 and D2 and Y4} (Month is invalid, Day is valid and Year is invalid)
I89 = {M4 and D3 and Y3} (Month is invalid, Day is valid and Year is invalid)
I90 = {M4 and D3 and Y4} (Month is invalid, Day is valid and Year is invalid)
I91 = {M4 and D4 and Y3} (Month is invalid, Day is valid and Year is invalid)
I92 = {M4 and D4 and Y4} (Month is invalid, Day is valid and Year is invalid)
I93 = {M5 and D1 and Y3} (Month is invalid, Day is valid and Year is invalid)
I94 = {M5 and D1 and Y4} (Month is invalid, Day is valid and Year is invalid)
I95 = {M5 and D2 and Y3} (Month is invalid, Day is valid and Year is invalid)
I96 = {M5 and D2 and Y4} (Month is invalid, Day is valid and Year is invalid)
I97 = {M5 and D3 and Y3} (Month is invalid, Day is valid and Year is invalid)
I98 = {M5 and D3 and Y4} (Month is invalid, Day is valid and Year is invalid)
I99 = {M5 and D4 and Y3} (Month is invalid, Day is valid and Year is invalid)
I100 = {M5 and D4 and Y4} (Month is invalid, Day is valid and Year is invalid)
I101 = {M1 and D5 and Y3} (Month is valid, Day is invalid and Year is invalid)
I102 = {M1 and D5 and Y4} (Month is valid, Day is invalid and Year is invalid)
I103 = {M2 and D5 and Y3} (Month is valid, Day is invalid and Year is invalid)
I104 = {M2 and D5 and Y4} (Month is valid, Day is invalid and Year is invalid)
I105 = {M3 and D5 and Y3} (Month is valid, Day is invalid and Year is invalid)
I106 = {M3 and D5 and Y4} (Month is valid, Day is invalid and Year is invalid)
I107 = {M1 and D6 and Y3} (Month is valid, Day is invalid and Year is invalid)
I108 = {M1 and D6 and Y4} (Month is valid, Day is invalid and Year is invalid)
I109 = {M2 and D6 and Y3} (Month is valid, Day is invalid and Year is invalid)
I110 = {M2 and D6 and Y4} (Month is valid, Day is invalid and Year is invalid)
I111 = {M3 and D6 and Y3} (Month is valid, Day is invalid and Year is invalid)
I112 = {M3 and D6 and Y4} (Month is valid, Day is invalid and Year is invalid)
I113 = {M4 and D5 and Y3} (All inputs are invalid)
Software Testing 377
I114 = {M4 and D5 and Y4} (All inputs are invalid)
I115 = {M4 and D6 and Y3} (All inputs are invalid)
I116 = {M4 and D6 and Y4} (All inputs are invalid)
I117 = {M5 and D5 and Y3} (All inputs are invalid)
I118 = {M5 and D5 and Y4} (All inputs are invalid)
I119 = {M5 and D6 and Y3} (All inputs are invalid)
I120 = {M5 and D6 and Y4} (All inputs are invalid)
The test cases generated on the basis of input domain are given in Table 9.23.
(Contd.)
378 Object-Oriented Software Engineering
(Contd.)
Software Testing 379
(Contd.)
380 Object-Oriented Software Engineering
There are two types of decision tables. The first type is called the limited entry decision
table where input values represent only the true and false condition as shown in Table 9.25.
Software Testing 381
Table 9.25 Limited entry decision table
Condition stub Condition entry
c1 T F F F F
c2 - T F F F
c3 - - T F F
- - - T F
a1 X X
a2 X X
a3 X X
Every column of the decision table represents a rule and generates a test case. A ‘-’ in the
condition entry represents a ‘do not care’ condition. An ‘X’ in the action entry represents the
action mentioned in the corresponding action stub. In Table 9.25, if condition c1 is true, then c2,
c3 and c4 become ‘do not care’ conditions and actions a1 and a3 are to be performed.
The second type of decision table is called extended entry decision table. In such a table,
multiple conditions are used instead of true and false conditions. A condition may have many
options instead of only true and false and such options are represented in the extended entry
decision table.
We consider a program which takes a date as an input and checks whether it is a valid date
or not. We prepare the following classes (options) and represent them in the extended entry
decision table as shown in Table 9.26.
I1 = {M1 : Month has 30 days}
I2 = {M2 : Month has 31 days}
I3 = {M3 : Month is February}
I4 = {M4 : Month <1}
I5 = {M5 : Month > 12}
I6 = {D1 : 1 Day 28}
I7 = {D2 : Day = 29}
I8 = {D3 : Day = 30}
I9 = {D4 : Day = 31}
I10 = {D5 : Day < 1}
I11 = {D6 : Day > 31}
I12 = {Y1 : 1900 Year 2058 and is a common year}
I13 = {Y2 : 1900 Year 2058 and is a leap year}
I14 = {Y3 : Year < 1900}
I15 = {Y4 : Year > 2058}
In the decision table, various combinations of conditions are considered and that may
sometimes result into an impossible action. In such a situation, we may incorporate an additional
action ‘impossible condition’ in the action stub. We may change the design of equivalence classes
to reduce the impossible conditions.
Table 9.26 Decision table of date program
382
Test case 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
c1 : Months in M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M2 M2
c2 : Days in D1 D1 D1 D1 D2 D2 D2 D2 D3 D3 D3 D3 D4 D4 D4 D4 D5 D6 D1 D1
c3 : Years in Y1 Y2 Y3 Y4 Y1 Y2 Y3 Y4 Y1 Y2 Y3 Y4 Y1 Y2 Y3 Y4 - - Y1 Y2
Rule count 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 1 1
a1 : Invalid date X X
a2 : Valid date X X X X X X X X
a3 : Input out of range X X X X X X X X X X
Test case 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
c1 : Months in M2 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2 M2 M3
Object-Oriented Software Engineering
c2 : Days in D1 D1 D2 D2 D2 D2 D3 D3 D3 D3 D4 D4 D4 D4 D5 D6 D1
c3 : Years in Y3 Y4 Y1 Y2 Y3 Y4 Y1 Y2 Y3 Y4 Y1 Y2 Y3 Y4 - - Y1
Rule count 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 1
a1 : Invalid date
a2 : Valid date X X X X X X X
a3 : Input out of range X X X X X X X X X X
Test case 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
c1 : Months in M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3 M4 M5
c2 : Days in D1 D1 D1 D2 D2 D2 D2 D3 D3 D3 D3 D4 D4 D4 D4 D5 D6 - -
c3 : Years in Y2 Y3 Y4 Y1 Y2 Y3 Y4 Y1 Y2 Y3 Y4 Y1 Y2 Y3 Y4 - - - -
Rule count 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24 24
a1 : Invalid date X X X X X
a2 : Valid date X X
a3 : Input out of range X X X X X X X X X X X X
Software Testing 383
Decision tables are used in situations where an output is dependent on many input conditions.
Complex relationships can also be easily represented in such tables. Every column may generate
a test case. The test cases of decision Table 9.26 are given in Table 9.27.
Decision tables are effectively applicable to small-size programs. As the size increases,
handling becomes difficult and time consuming. We can easily apply the decision table at the
unit level. System testing and integration testing do not find its applicability in any reasonable-
size program.
EXAMPLE 9.7 Consider a program to multiply and divide two numbers. The inputs may be
two valid integers (say a and b) in the range of [0, 100]. Develop the decision table and generate
test cases.
Solution The decision table is given in Table 9.28 and the test cases are given in Table 9.29.
Software Testing 385
Table 9.28 Decision table for a program to multiply and divide two numbers
Input in valid range? F T T T T
a = 0? - T T F F
b = 0? - T F T F
Input values out of range X
Valid output X X
Output undefined X
Divide by zero error X
Table 9.29 shows the test cases generated from the above decision table.
Table 9.29 Test cases for decision table shown in Table 9.28
Test case a b Expected output
1 50 –1 Input values are out of range
2 0 0 Output undefined
3 0 50 0 0
4 30 0 Divide by zero error
5 50 50 2500 1
The program graph provides the graphical view of the program and may become the
foundation of many testing techniques. The fundamental constructs of the program graph are
given in Figure 9.7.
386 Object-Oriented Software Engineering
#include<stdio.h>
#include<conio.h>
1 void main()
2 {
3 int num;
4 clrscr() ;
5 cout<<"Enter number" ;
6 cin>>num ;
Figure 9.8 (Contd.)
Software Testing 387
7 if(num%2==0)
8 {
9 cout<<"Number is even";
10 }
11 else
12 {
13 cout<<"Number is odd";
14 }
15 getch();
16 }
Figure 9.8 Program to determine whether a number is even or odd.
A path in a graph is a sequence of adjacent nodes where nodes in sequence share a common
edge or sequence of adjacent pair of edges where edges in sequence share a common node. It is
clear from the program graph that there are two paths in the graph.
These paths are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 16 and 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 16.
Every program graph has one source node and one destination node. In the program graph given
in Figure 9.9, nodes 1 to 6 are in sequence, node 7 has two outgoing edges (predicate node) and
node 15 is a junction node.
A program graph can be converted into a DD program graph. There are many nodes in
the program graph which are in a sequence like nodes 1 to 6 of the program graph given in
Figure 9.9. When we enter into the sequence through the first node, we can exit only from the
last node of the sequence. In the DD path graph, all nodes which are in a sequence are combined
and represented by a single node. The DD path graph is a directed graph in which nodes are the
388 Object-Oriented Software Engineering
sequence of statements and edges are the control flow amongst the nodes. All DD path graphs have
a source node and a destination node similar to the program graph. A mapping table is prepared
to match the nodes of the DD path graph to the corresponding nodes of the program graph. All
sequential nodes are combined into a single node which reduces the size of the DD path graph.
Mapping table of the program graph given in Figure 9.9 is presented in Table 9.30.
The corresponding DD path graph is given in Figure 9.10. There are two paths, namely, S,
N1, N2, N3, N5, D and S, N1, N2, N4, N5, D. Paths in the program are identified from the DD
path graph easily. We may like to see the behaviour of the program when every identified path
is executed. Hence, we may design test cases in such a way that at least every identified path is
executed during testing.
Cyclomatic complexity also provides some insight into the complexity of a module.
McCabe (1976) proposed an upper limit of cyclomatic complexity to 10 with significant
supporting evidence. We may go up to 15 in today’s scenario of new programming languages,
availability of CASE tools, effective validation and verification techniques, and implementation
of software engineering principles and practices. If the limit further exceeds, it is advisable to
redesign the module and maintain the cyclomatic complexity within prescribed limits.
The program graph may generate a few paths which are impossible in practice. When we
give inputs, some paths may not be possible to traverse due to logic of the program. Hence, some
paths are impossible to create and traverse and cannot be implemented. Path testing ensures
100% statement and branch coverage and guarantees a reasonable level of confidence about the
correctness of the program.
#include<stdio.h>
#include<conio.h>
1 void main()
2 {
3 int a,b,c,validInput=0,d;
4 clrscr();
5 cout<<"Enter values of a, b & c:\n";
6 cin>>a>>b>>c;
7 if((a>=0)&&(a<=100)&&(b>=0)&&(b<=100)&&(c>=0)&&(c<=100)){
8 validInput=1;
9 if(a==0){
10 validInput=-1;
11 }
12 }
13 if(validInput==1){
14 d=b*b-4*a*c;
15 if(d==0){
16 cout<<"Equal roots";
17 }
18 else if(d>0){
19 cout<<"Real roots";
20 }
21 else{
22 cout<<"Imaginary roots";
23 }
24 }
25 else if(validInput==-1){
26 cout<<"Not quadratic";
27 }
28 else {
29 cout<<"The inputs are out of range";
30 }
31 getch();
32 }
392 Object-Oriented Software Engineering
The activity diagram for finding the roots of a quadratic equation is given in Figure 9.11.
Figure 9.11 Activity diagram for finding the roots of a quadratic equation.
Cyclomatic complexity = 22 – 17 + 2 = 7
Software Testing 393
The test cases for independent paths are given in Table 9.32.
Queue
x: integer
front: integer
rear: integer
Queue( )
Insert(x)
Remove( )
Figure 9.12 Structure of the class ‘queue’.
We identify all pre- and postconditions for every operation of class ‘queue’. There are three
operations and their pre- and postconditions are given as:
(i) Operation Queue: The purpose of this operation is to create a queue
Queue::queue( )
(a) Pre = true
(b) Post: front = 0, rear = 0
(ii) Operation Insert(x): This operation inserts an item x into the queue.
Queue::insert(x)
(a) Pre: rear < MAX
(b) Post: rear = rear + 1
(iii) Operation Remove( ): This operation removes an item from the front side of the queue.
Queue::remove( )
(a) Pre: front > 0
(b) Post: front = front + 1
We establish logical relationships between identified pre- and postconditions for insert(x) and
remove() operations.
Insert(x):
1. (precondition: rear < MAX; postcondition: rear = rear + 1)
2. (precondition: not (rear < MAX); postcondition: exception)
Similarly for remove( ) operation, the following logical relationships are established:
3. (precondition: front > 0; postcondition: front = front + 1)
4. (precondition: not (front > 0); postcondition: exception)
Test cases are generated for every established logical relationship of pre- and postconditions.
Test cases for insert(x) and remove( ) operations are given in Table 9.33.
We should not confuse with the start state and end state of the statechart diagram. a and w
are additional states and are represented explicitly in the statechart diagram. We consider an
example of a class ‘queue’ with two operations—insert and remove. The queue is based on
the principle of FIFO (first in first out) and there are three states: empty, holding and full. In
addition to these three states, two additional states a and w are also used. There are four events,
namely, new, insert, remove and destroy with the following objectives:
New: Creates an empty queue.
Insert: Inserts an element in the queue, if space is available.
Remove: Removes an element from the queue, if it is available.
Destroy: Destroys the queue after the completion of its requirement, i.e. object of the
queue class is destroyed.
We may draw the statechart diagram of the queue class as given in Figure 9.13.
The statechart diagram gives the graphical view of the behaviour of the system. All
transitions are shown along with self-loop type transitions. In the above statechart diagram, the
holding state has two self-loops for the following purposes:
(i) When [rear < MAX – 1], we insert an element x and the same state is maintained.
(ii) When [front > 1], we remove an element, the same state is maintained.
If the number of states increases, it becomes difficult to draw the statechart diagram and keep
track of various transitions. In practice, the number of states is very large (more than 100 also)
and it may not be possible to draw a statechart diagram. Another option is to represent the
statechart diagram’s information in tabular form and this table is known as state transition
table. The row of the table represents the present state and the column represents the resultant
state. The state transition table of ‘queue’ class is given in Table 9.34. The state transition table
incorporates every information of the statechart diagram such as transitions, events and actions,
and may become the basis to design the test cases.
new √
insert(x)
remove()
destroy
Empty new
insert(x)
remove()
destroy √
Holding new
insert(x) √ √
remove() √ √
destroy √
Full new
insert(x)
remove() √
destroy √
These test cases are systematic and cover every functionality of the ‘queue’ class. The state-
based testing is simple, effective and systematically generates a good number of test cases.
time and resource constraints. We attempt to reduce the size on the basis of some techniques.
However, if we execute all test cases and do not find any fault in the program, there are the
following possibilities:
(i) Test suite is effective, but there are no faults in the program.
(ii) Test suite is not effective, although there are faults in the program.
In both possibilities, we could not make our program fail, although reasons of non-failure of the
program are different. In the first case, the quality of the program is good and there are no faults
in the program. However, in the second case, there are faults in the program but test cases are
not able to find them. Hence, mutation testing helps us to know the effectiveness of an existing
test suite with reasonable level of accuracy.
#include<iostream.h>
#include<conio.h>
1 class smallest
2 {
3 private:
4 int a,b,c;
5 public:
6 void getdata()
7 {
8 cout<<"Enter first number: ";
9 cin>>a;
10 cout<<"\nEnter second number: ";
11 cin>>b;
12 cout<<"\nEnter third number: ";
13 cin>>c;
14 }
15 void compute();
16 };
17 void smallest::compute()
18 {
19 if(a<b)
20 {
21 if(a<c)
22 {
23 cout<<"\nThe smallest number is:"<<a;
24 }
25 Else
26 {
27 cout<<"\nThe smallest number is:"<<c;
28 }
29 }
30 Else
31 {
32 if(c<b)
33 {
34 cout<<"\nThe smallest number is:"<<c;
35 }
36 Else
37 {
38 cout<<"\nThe smallest number is:"<<b;
39 }
40 }
41 }
42 void main()
43 {
44 clrscr();
45 smallest s;
46 s.getdata();
47 s.compute();
48 getch();
49 }
The mutant M1 is created by replacing the operator ‘<’ of line number 19 by the operator ‘=’. The
mutant M2 is created by replacing the operator ‘<’ of line number 32 by the operator ‘>’. These
400 Object-Oriented Software Engineering
changes are simple and both mutants are different than the original program. Both mutants are
also different than each other but are syntactically correct. The mutants are known as first-order
mutants. We may also get second-order mutants by making two changes in the program and
third-order mutants by making three changes and so on. The second-order and above mutants
are called higher-order mutants. However, in practice, we generally use only the first-order
mutants in order to simplify the process of mutation. The second-order mutants can be created
by making two changes in the program as shown in Figure 9.17.
The total number of mutants is equal to the number of killed mutants plus the number of live
mutants. A mutation score range is from 0 to 1. The higher value of a mutation score shows the
effectiveness of the test suite. If the mutation score is 0, it indicates that the test suite is not able
to detect any introduced fault in mutants and is useless for the program. The live mutants are
important and should be studied thoroughly. Special test cases should be designed to kill live
mutants. The new test cases which are able to kill live mutants should be added to the original
test suite to enhance its capability. The mutation testing not only assesses the capability of the
test suite but also enhances the capability by adding new test cases. Some of the popular tools
are insure++, Jester for Java, nester for C++, MuJava tool, Mothra, etc.
We consider the program given in Figure 9.14 to find the smallest of three numbers.
Table 9.36 shows the test suite available to test the program.
Table 9.36 Test suite to test the program given in Figure 9.14
S. No. A B C Expected output
1 3 1 5 1
2 6 2 8 2
3 4 5 7 4
4 8 6 3 3
5 9 10 6 6
The actual output of all mutants with existing test suite is given in Table 9.38.
The existing test suite kills five mutants (M1 to M5), but fails to kill mutant M6. Hence, a
mutation score is calculated as given below:
Number of mutants killed
Mutation score =
Total number of mutants
5
=
6
= 0.83
Effectiveness of a test suite is directly related to the mutation score. Mutant M6 is live here and
an additional test case is to be written to kill this mutant. The additional test case is created to
kill this mutant M6 and is given in Table 9.39.
When we execute this test case, we get the observed behaviour of the program given in Table 9.40.
This additional test case is very important and must be added to the given test suite. Therefore,
the revised test suite is given as in Table 9.41.
Software Testing 403
Table 9.41 Revised test suite
S. No. A B C Expected output
1 3 1 5 1
2 6 2 8 2
3 4 5 7 4
4 8 6 3 3
5 9 10 6 6
6 6 4 5 4
inspections and walkthroughs are easily applicable and may find a good number of faults. State-
based testing, path testing, class testing, boundary value analysis, equivalence class and decision
table-based testing techniques are also applicable.
Review Questions
1. What is software testing? Discuss issues, limitations, practices and future of software
testing.
2. “Testing is not related to only one phase of software development life cycle”. Comment
on the correctness of this statement.
3. Differentiate between verification and validation. Which one is more important and
why?
4. Which is the most popular verification technique? Explain with suitable examples.
5. Write short notes on the following verification techniques:
(a) Peer reviews
(b) Walkthroughs
(c) Inspections
6. Design an SRS document verification checklist. Highlight some important issues which
such a checklist must address.
7. What is a checklist? Discuss its significance and role in software testing.
8. Differentiate between walkthroughs and inspections. List the advantages and disadvantages
of both techniques.
9. Design checklists for OOA document and OOD document. Both checklists should cover
important issues of both documents.
10. Establish the relationship between verification, validation and testing along with suitable
examples.
11. What is functional testing? Discuss any one technique with the help of an example.
12. What is boundary value analysis? What are its extensions? List the advantages and
limitations of each extension.
13. Consider a program that determines the previous date and the next date. Its inputs are a
triple of day, month and year with its values in the following range:
1 month 12
1 day 31
1947 year 2011
The possible outputs are “next date”, “previous date” or “invalid input”. Design boundary
value analysis test cases, robust test cases, worst test cases and robust worst test cases.
408 Object-Oriented Software Engineering
14. Consider a program that calculates median of three numbers. Its input is a triple of
positive integers (say a, b and c) and values are from the interval [1, 1000]. Generate
boundary value and robust test cases.
15. Describe the equivalence class testing technique. How is it different from boundary
value analysis?
16. What is decision table-based testing? What is the role of a rule count? Discuss the
concept with an example.
17. Consider a program to sort a list in ascending order. Write test cases using equivalence
class testing and decision table-based testing.
18. What are the limitations of boundary value analysis? Highlight the situations in which
it is not effective.
19. Consider a program that counts the number of digits in a number. The range of input is
given as [1, 1000]. Design the boundary value analysis and equivalence class test cases.
20. What is structural testing? How is it different from functional testing?
21. What is path testing? How can we make it more effective and useful?
22. Show that a very high level of statement coverage does not guarantee a defect-free
program. Give an example to explain the concept.
23. What is mutation testing? What is the significance of mutation score? Why are higher-
order mutants not preferred?
24. Why is mutation testing becoming popular? List some significant advantages and
limitations.
25. What is a program graph? How can it be used in path testing?
26. Define the following:
(a) Program graph
(b) DD path graph
(c) Mapping table
(d) Independent paths
27. What is class testing? Why should unspecified behaviour not be implemented?
28. What is state-based testing? What are alpha and omega states? List the advantages and
limitations of the state-based testing.
29. What are levels of testing? Which level is most popular and why?
30. Explain the concept of flattening of classes. How can it help in unit testing?
31. Discuss the importance of software testing tools. List some static, dynamic and process
management tools.
32. Differentiate between static and dynamic testing tools. Which one is more effective and
why?
33. “Some non-functional requirements cannot be tested without using a software testing
tools”. Comment on this statement and justify with an example.
Software Testing 409
34. Differentiate between black box testing and white box testing. Consider a program to
find the smallest number amongst three numbers. Generate test cases using one of the
testing techniques.
35. Write short notes on:
(a) Software testing tools
(b) State-based testing
(c) Class testing
Further Reading
Fagan shows that by using inspection, the cost of errors may be reduced significantly in initial
phases of software development:
Fagan, M.E., Design and code inspections to reduce errors in program development. IBM Systems
Journal, 15(3): 182–211, 1976.
Strauss et al. provide a comprehensive guide to software inspections method that may reduce
program defects in the early phases of software design and development:
Strauss, S.H., Susan, H., and Ebenau, Robert G., Software Inspection Process. New York:
McGraw-Hill, 1994.
Yourdon’s book may provide a useful guidance to practitioners and programmers on group
walkthroughs:
Yourdon, E., Structured Walkthroughs. Englewood Cliffs, NJ: Prentice-Hall, 1989.
The below book is resource for pre-1981 literature and contains a huge bibliography up to and
including 1981:
Miller, E.F. and Howden, W.E., Tutorial: Software Testing and Validation Techniques.
New York: IEEE Computer Society, 1981.
A hands-on guide to the black box testing technique:
Beizer, B., Black-Box Testing: Techniques for Functional Testing of Software and Systems.
New York: John Wiley & Sons, 1995.
An introductory book on software testing with a special focus on functions testing is:
Jorgensen, P.C., Software Testing: A Craftsman Approach, 3rd ed. New York: Auerbach
Publications, 2007.
A useful guide for designing test cases for object-oriented applications. This book provides
comprehensive and detailed coverage of techniques to develop testable models from unified
modelling language and state machines:
Binder, R.V., Testing Object Oriented Systems: Models, Patterns and Tools. Reading,
MA: Addison-Wesley, 1999.
Software Testing 413
Binder has significantly contributed in the area on object-oriented testing:
Binder, R., State-based testing. Object Magazine. 5(4): 75–78, July–Aug, 1995.
Binder, R., State-based testing: sneak paths and conditional transitions. Object Magazine, 5(6),
87–89, Nov–Dec, 1995.
Binder, R., Testing Object-Oriented Systems: A Status Report, Released online by RBSC
Corporation, 1995. Available at http://stsc.hill.af.mil/crosstalk/1995/April/testinoo.asp
McGregor and Sykes provide good differences of testing traditional and object-oriented software.
They also describe methods for testing of classes:
McGregor, J.D. and Sykes, David A., A Practical Guide to Testing Object Oriented Software.
Canada: Addison–Wesley, 2001.
A complete bibliographical list on object-oriented testing can be obtained from:
http://oo-testing.com/bib/
A study on mutation analysis on object-oriented programs can be found in:
Ma, Y.S. and Kwon, Y.R., A study on method and tool of mutation analysis for object-oriented
programs. Software Engineering Review, 15(2): 41–52, 2002.