You are on page 1of 4

2014 Fourth International Conference on Advanced Computing & Communication Technologies

A Study on Object-Oriented Testing Technique and Object-Oriented Metrics useful


in Reducing Class Testing Complexity

Brij Mohan Goel


Department of Computer Science and Applications
Vaish College of Engineering
Rohtak, India
brijmohan.vce@gmail.com

Abstract—Testing the inherited features is clearly essential; Li and Henry [9] proposed three groups of object-oriented
however, the testing process can easily become very complex if metrics to evaluate the maintenance efforts of two
features in the child classes are unnecessarily tested. In this commercial systems. However, all of these proposed object-
paper, an object-oriented testing technique "Inheritance oriented metrics mechanisms only focus on measuring the
Testing in Classes" (ITC) is proposed that facilitates the testing empirical relationships between a set of objects and pay little
of object-oriented code by incorporating procedures to support
attention to the inheritance relationships between objects and
inheritance testing. ITC provides a framework that helps to
the metrics of an inheritance hierarchy. Nevertheless, there
ensure that appropriate components and interactions are
tested by generating code segments that drive the testing are several methods for testing software inheritance relations
process. ITC is developed and tested using the object-oriented appeared in the literature [10, 11].
(OO) paradigm.
Software reuse reduces the amount of software that needs
Keywords-Testing Complexity, CK Metrics, Inheritance, to be produced from scratch and hence less testing time for
Object-Oriented Metrics new software. Inheritance allows a subclass to "legally" use
everything in its superclass. Inheritance is viewed as an
I. INTRODUCTION addition, i.e., adding a method to an object in a class that
differs from the methods in the super class. Inheritance,
Testing the functionality of a program must be planned which is either multilevel or multiple, facilitates and
and designed before the coding stage. Programs are tested encourages reusability. With multilevel inheritance, a class is
using various testing techniques to uncover errors to produce derived from another derived class. With multiple
high quality programs; however, different software Inheritance, a class is permitted to have more than one
paradigms require different testing techniques. Effective and superclass. Multiple Inheritance increases the possibility of
successful testing helps to reduce maintenance of software. code sharing and increases the possibility of conflicts. With
Testing, if done properly, facilitates the timely delivery of hierarichal inheritance the traits of one class may be
systems. inherited by more than one class.
Software testing techniques are used to detect errors in The customizing process involves the following steps:
software. Software metric strategies serve as monitors to 1) define a test plan by devising possible components of
measure the complexity of the software. Both software a test plan and then analyzing the design,
testing and metrics are useful mechanisms to improve the
2) generate the test plan,
technical quality of software products. Many testing
methodologies for procedure oriented languages that detect 3) implement the test plan, and
control flow and data flow errors have been proposed [4, 5, 4) analyze results.
6]. Also, many researchers have introduced metrics
techniques [7, 8]. However, these techniques are not In theory, the designer develops a test plan during the
sufficient for software development in the object-oriented design stage. The tester applies testing techniques based
paradigm due to the new data and control abstractions, such upon the test plan, corrects the errors, and retests the plan
as inheritance, instantiation, polymorphism, and message until he or she achieves the final product. Section 2
passing. Thus, in order to analyze programs which are coded introduces the testing techniques. Section 3 describes the
in an object-oriented programming language, there exists the Object-Oriented metrics. Section 4 is devoted to the
need of developing object-oriented software measurement implementation of ITC and Section 5 defines the inheritance
and testing mechanisms. Recently, complexity studies have test complexity estimation. Finally, a conclusion is
been attempted to consider object-oriented software systems. presented.
Chidamber and Kemerer [2] have contributed six object-
II. OO SOFTWARE TEST STRATEGY
oriented metrics (i.e., WMC, DIT, NOC, CBO, RFC, and
LCOM) to the development and empirical validation of a set The classical strategy for testing computer software begins
of theoretically-grounded metrics of object-oriented designs. with “testing in the small” and works outward toward

978-1-4799-4910-6/14 $31.00 © 2014 IEEE 185


DOI 10.1109/ACCT.2014.60
“testing in the large”. In software testing, we begin with unit validation of OO software focuses on user-visible actions
testing, then progress toward integration testing, and close and user-recognizable output from the system. To assist in
with validation and system testing. In conventional the derivation of validation tests, the tester should draw upon
applications, unit testing focuses on the smallest compliable the use-cases that are part of the analysis model. The use-
program unit the subprogram (e.g., module, subroutine, case provides a scenario that has a high likelihood of
procedure, and component). Once each of these units has uncovered errors in user interaction requirements.
been tested individually, it is integrated into a program Conventional black box testing methods can be used to drive
structure while a series of regression tests are run to uncover validations tests. In addition, test cases may be derived from
errors due to interfacing between the modules and side the object-behavior model and from event flow diagram
created as part of object oriented analysis (OOA).
effects caused by the addition of new units. Finally, the
system as a whole is tested to ensure that errors in III. OBJECT-ORIENTED METRICS
requirements are uncovered [1].
Almost all research in the field of object-oriented metrics
A. Unit Testing in the OO Context has been directed towards association with source code a
When object-oriented software is considered, the concept complexity number. However class complexity evaluation
of the unit changes. Encapsulation drives the definition of after a class code had been already written may be too
classes and objects. This means that each class and each expensive. In a widely cited paper Chidamber and Kemerer
instance of a class (object) packages attributes (data) and the [2] introduced six object-oriented metrics based upon
operations (also known as methods or services) that measurement theory. The proposed set of metrics is as
manipulate these data. Rather than testing an individual follows:
module, the smallest testable unit is the encapsulated class or
object. Because a class can contain a number of different 1) Number of Children - NOC
operations and a particular operation may exist as part of a 2) Depth of Inheritance Tree - DIT
number of different classes, the meaning of unit testing 3) Weighted Methods per Class - WMC
changes dramatically. We can no longer test a single 4) Response for a Class - RFC
operation in isolation (the conventional view of unit testing) 5) Coupling between Objects - CBO
but rather as part of a class. 6) Lack of Cohesion in Methods - LCOM
B. Integration Testing in the OO Context
In their paper Chidamber-Kemerer [2] also provides an
Because object-oriented software does not have a analytical confrontation of their proposed metrics with
hierarchical control structure, conventional top-down and Weyuker’s [3] list of measurement principles.
bottom-up integration strategies have little meaning. In
addition, integrating operations one at a time into a class (the The NOC metric is defined as the count of immediate
conventional incremental integration approach) is often subclasses. If a class has a large NOC value, it may require
impossible because of the “direct and indirect interactions of more testing of the methods in that class.
the components that make up the class”.
There are two different strategies for integration testing DIT is the length of the maximal path to the root of the
of OO systems: class hierarchy. It can be observed that the deeper is a class
1) The first, thread-based testing, integrates the set of in the hierarchy, the greater can be the number of inherited
classes required to respond to one input or event for the methods making it more difficult to predict its behaviour so
system. Each thread is integrated and tested individually. more effort is needed in testing this class. Deeper trees
Regression testing is applied to ensure that no side effects constitute greater design complexity, since more methods
occur. and classes are involved.
2) The second integration approach, use-based testing,
begins the construction of the system by testing those WMC is the count of methods in a class. The number of
classes (called independent classes) that use very few (if methods and its complexity is a predictor of how much time
and effort is required to develop and maintain the class.
any) of server classes. After the independent classes are
Classes with large number of methods are likely to be more
tested, the next layer of classes, called dependent classes, application specific, limiting the possibility of reuse. The
that use the independent classes are tested. This sequence of more methods defined in a class the greater is its possible
testing layers of dependent classes continues until the entire impact on children, since children inherit all defined
system is constructed. Unlike conventional integration, the methods.
use of drivers and stubs as replacement operations is to be
avoided, when possible. The RFC metric is the cardinality of the set of all
methods that can be potentially executed in the response to
C. Validation Testing in an OO Context the arrival of a message to an object. RFC is a measure of the
At the validation or system level, the details of class potential communication between the class and another
connections disappear. Like conventional validation, the classes. If a large number of methods can be invoked in

186
response to a message, the testing and debugging of the class (overriding) or 3) adding separate code (pure) forces
becomes more complicated since it requires a greater level of different testing approaches.
understanding required on the part of the tester. The larger
the number of methods that can be invoked from a class, the The inheritance testing in classes is done through pure
greater the complexity of the class. A worst case value for (non inherited), inherited, and overridden methods. We will
possible responses will assist in appropriate allocation of test all pure methods, retest all overridden methods, but will
testing time. RFC does not count calls to X- library functions not test inherited methods. Some test drivers are needed
and 110 functions like printf, scanf that are present in C++, since inherited methods are assumed to be tested earlier in
interface classes are counted in RFC. the object level test of the parent. Therefore, only pure and
overridden methods have to be tested.
The CBO metric is approximately defined as the number
of couples with other classes (where calling a method or V. INHERITANCE TEST COMPLEXITY ESTIMATION
using instance variable from another class constitutes To assist with ITC, we present an inheritance test
coupling). The more independent a class is, the easier it is to complexity estimator. The estimator helps the tester to
reuse it in another application. To improve modularity and evaluate how much testing is needed. It is based on the sum
promote encapsulation inter class coupling should be small. of methods that require testing or retesting. The number of
The larger the number of couples, the higher is the sensitivity inherited methods in a certain object, say ȗ can be added to
to changes in other parts of the design and therefore the complexity estimation if they were not tested at the
maintenance is more difficult. CBO metric is useful to parent level. The estimator is defined by:
determine how complex the testing of various parts of a
design is likely to be. The higher the CBO is, the more Cc= P+ O+ I
rigorous the testing needs to be. CBO depends on the manner Where
in which methods are designed and not on the functionality
of the class. P = Pure methods
O = Inherited overridden methods
The LCOM metric is defined as a count of the method
pairs that do not have common instance variable minus the I = Inherited methods not tested at the parent level
count of method pairs that do. The larger the number of C = Complexity of inheritance testing
similar methods, the more cohesive is the class. If none of
the methods of a class display any instance behaviour, i.e. do C, is the inheritance test complexity estimation for class
not use any instance variables, they have no similarity and ȗ. Recall that we want to test pure methods and retest
the LCOM for the class will be zero. Cohesiveness of overridden methods but we do not test inherited methods. As
methods within a class is desirable, since it promotes an example of estimating the number of test stubs required,
encapsulation. Lack of cohesion implies classes should be assume that their exist a class called ȗ with two methods and
probably split into two or more subclasses. Any measure of three member objects: O1, O2, O3. Let O1 have three pure
disparity of methods helps identify flaws in the design of methods and one overridden method, let O2 have four pure
classes. Low cohesion increases complexity, thereby methods and two overridden methods, and let O3 have two
increasing the likelihood of errors during the development pure methods and no overridden methods. The following
process. formula determines the estimation:

IV. INHERITANCE TESTING IN CLASSES (ITC) C(O1) = 3 + 1 + n (not tested in parent) = 4 + n


ITC is done after the object has been tested at the (unit) C(O2) = 4 + 2 + n (not tested in parent) = 6 + n
object level. Testing the object at the global level, i.e., the C(O3) = 2 + 0 + n (not tested in parent) = 2 + n
range of all possible parents from whom the object can
inherit methods, is needed. Testing the inheritance of an Then for the class ȗ, Cȗ = ™Ci = C(O1) + C(O2) + C(O3)
object must be done if the various forms exist in that object: = 4 + 6 + 2 + 3(n), where n is the number of methods not
multilevel (inheritance from a parent that already inherited tested in the parent.
from its own parent) or multiple (inheritance from more than
single parent) or hierarichal (inherited by more than one This result helps in planning the testing procedure after
class from one parent class). All inherited methods in the the design and coding are completed. The execution of this
scope of one object have to be considered for option can be written in the test plan to be run after the
testing/retesting based on the nature of their use. coding of every object is done.
VI. CONCLUSION
The test is Inheritance Testing in Classes (ITC). It targets
the multiple, multilevel and hierarchical inheritance in an In this article, Inheritance Testing in Classes (ITC)
object of a class. When an object inherits from a parent class, testing technique used for reducing class testing complexity
it inherits all methods and data structures. Within OO, in object-oriented paradigm. The higher the ITC value is; the
choosing among the possibilities of 1) inheriting the code greater the potential reuse of inherited methods; the greater
and reusing it, 2) inheriting the code and altering it the number of methods it is likely to inherit, making it more

187
complex to predict its behavior; the greater design [4] T. JI. McCabe, “Design Complexity Measurement and Testing”,
complexity, since more methods and classes are involved ACM 32:1415-1425, 1989.
and therefore more difficult maintenance; the greater the [5] S. C. Ntafos, “On Required Element Testing”, IEEE Transactions on
Software Engineering”, SE-10(6):795-803, 1984.
likelihood of improper abstraction of the parent class. If a
class has a large number of children, it may be a case of [6] S. Rapps, E. J. Weyuker, “Selection Software Test Data using Data
Flow Information, IEEE Transactions on Software Engineering, SE-
misuse of sub classing. The higher the ITC value is; the more 11(4):367-375, 1985.
effort is needed in testing. ITC can replace DIT metric or [7] H. E. Dunsmore, J. D. Gannon, Data Referencing: An Empirical
NOC metric in the prediction of testing effort. Investigation”, IEEE Computer, December:50-59, 1983.
[8] W. A. Harrison, K. I. Magel, “A Complexity Measure based on
REFERENCES Nesting Level”, ACM SIGPLAN Notes, 16(3):63-74, 1981.
[1] S. Gambir, "Testing Strategies for Object Oriented Systems", [9] W. Li and S. Henry, Object-oriented metrics that predict
IRACST - International Journal of Computer Science and maintainability, J. Systems and Software 23:111-122, 1993.
Information Technology & Security (IJCSITS), Vol. 2, No. 2, pp. [10] M. Barrold, J. D. McGregor, and K. Fitzpatrick, “Incremental Testing
459-462, April 2002 of Object-Oriented Class Structure”, Proceedings of the 14th
[2] S. R. Chidamber, C. F. Kemerer, “A Metrics Suite for Object- International Conference on Software Engineering, pp. 68-80, 1992.
Oriented Design”, IEEE Transactions on Software Engineering, Vol. [11] S. Kirani, W. T. Tsai, “Method Sequence Specification and
20, No. 6, pp. 476-492, June 1994. Verification of Class," Journal of Object-Oriented Programming,
[3] E. Weyuker, “Evaluating Software Complexity Measures”, IEEE 7(5):28-38, 1994.
Transactions on Software Engineering, Vol. 14, No. 9, pp. 1357-
1365, September 1988.

188