Docsity

Object-Oriented Testing: Approaches and Challenges - Prof. Wei-Tek Tsai, Study notes of Computer Science

Partial preview of the text

Download Object-Oriented Testing: Approaches and Challenges - Prof. Wei-Tek Tsai and more Study notes Computer Science in PDF only on Docsity!

1

Testing Object-Oriented

Software

Wei-Tek Tsai

Department of Computer Science and

Engineering

Arizona State University

Tempe, AZ 85287

2

Content

• Introduction

• Object-Oriented Testing

3

Introduction

  • Motivation
    • Many modern embedded systems use OOLs as the implementation languages and employ UML as the design language.
    • “Object-oriented development will experience different types and proportions of errors that require a different approach to testing.” [Binder 1996, p.127]
    • “In OO, testing is continuously interwoven into the development process.” [Binder 1996, p. 228]
    • “In OO testing, a tester often needs to answer questions like to test this class what other classes must be tested?” [Binder 1996, p.199]

4

Introduction

• Using object-oriented languages decreases

the amount of testing need.

  • “the technology and software process

associated with object-oriented development

obviates or greatly reduces the need for testing”

[Binder 1996, p.126]

7

• OOT begins by evaluating correctness and

consistency of OOA and OOD models

• Testing OOA/OOD model

  • Useful to avoid to add accommodate

unnecessary attributes to subclasses

  • Useful to avoid incorrect or extraneous class

relationships

  • Useful to avoid improper behavior to

accommodate extraneous attributes

8

Object-oriented Testing

  • Testing OOA/OOD models
    • Correctness
      • Judge by conformance with real world domain
      • Syntactic (notation, conventions)
      • Semantic (conforms to real problem)
    • Consistency
      • Check CRC and object-relationship models for inclusion of all collaborations
      • Ensure that delegated responsibilities are part of collaborator’s definition
      • Ensure that each collaborator is receiving requests from proper source

9

• Testing OOA/OOD Models

  • Consistency
    • Use inverted connection to determine whether other classes or responsibilities are needed.
    • Determine whether widely requested responsibilities might be combined, e.g., read credit card and get authorization.
    • Iterate on the above.

10

Object-oriented Testing

  • Testing OOA/OOD Models
    • Use CRC index card for models review

13

• Unit Testing

  • “Classes are not testable per se, but class testing

is crucial for reuse so “testing should be

thorough … completely unit testing a single

instance, completely unit testing its

corresponding class.” (Firesmith, 1992 and

1995)” [Binder 1996, p. 161]

14

Object-oriented Testing

• Unit Testing

  • Unit testing is used to ensure that each unit

meets its specification.

  • Classes are the proper subject of unit testing
    • Smallest stand-alone unit for testing
      • Instantiation of a single class
    • Some minimal integration usually required
      • Instance variables typically instances of other classes
    • The class under test and a minimal set of server classes is called a class cluster

15

• Unit Test

  • Unit testing may begin when a class is implemented.
  • If the class is not a derived class
    • Unit testing is equivalent to that in a traditional system
  • If the class is a derived class
    • Thoroughly test the parent class;
    • Test the derived class in conjunction with the base class
  • Message passing and inheritance influence how much testing will be needed.

16

Object-oriented Testing

  • Testing Strategies changes – Integration Testing
    • Integration Testing
      • Thread-based
      • Use-based (dependent & independent classes)
    • Integration is not hierarchical in OO
      • Coupling is not via subroutine
      • “Top-down” and “Bottom-up” have little meaning
    • Integrating one operation at a time is difficult
      • Indirect interactions among operations

19

  • Test Case Design
    • Testing must be based on an assumption about where faults are likely to be found. - Called a fault hypothesis
    • Based on the fault hypothesis, there are different test case design models
    • Each model will focus on the sequences of operations to exercise the states of a class instance
    • The test case design model
      • A representation ( black-box test case design methods)
      • An implementation (white-box test case design methods)

20

Object-oriented Testing

• Challenge in OO:

  • Encapsulation:
    • Can we inspect the inner state of an object?
  • Inheritance:
    • Can test cases for a super class be used to test a subclass?

21

  • Test Case Design [Berard 93]
    • Identify unique tests & associate with a particular class
    • Describe purpose of the test
    • Develop list of testing steps:
      • Specified states to be tested
      • Messages and operations (methods) to be tested
      • Exceptions that might occur
      • External conditions & changes thereto
      • Supplemental information

22

Object-oriented Testing

• “…typical features of object-oriented

system require new approaches to adequate

testing, beneficial effects of class

modularity notwithstanding.”

[Binder 1996, p. 126]

25

• Encapsulation

  • The purpose of encapsulation is to restrict the

usage of global data structures and to separate

logically different parts of the program.

  • Example:
    • class Stack { void push(element obj); element pop(void); }

26

Object-oriented Testing

• Encapsulation

  • Refers to the access control mechanisms that

determine visibility of element in objects

  • The internal data and state information is

hidden from other objects. They can access this

data only via methods that the object provides

27

Object-oriented Test

• Encapsulation

  • For this feature, calling the methods of an

object in a wrong order, it should lead to a

problem.

  • It is not enough to assume that no one ever calls

the methods in the wrong order in test cases.

28

Object-oriented Testing

  • Inheritance
    • Inheritance is an object-oriented technique to model real-world relationships in a software system. It can clarify the software structure and help to design reusable program object.
    • Inheritance is the technique to reuse code.
    • Inheritance may weaken encapsulation. Normally, programmers have to know the implementation of the super class to use the inheritance correctly.

31

• Inheritance

  • Bug hazards related to inheritance
    • A specialized method does not call the corresponding super class method.
    • An overridden method is called by another public not overridden super class method.
    • Missing override or specialization in subclass.
    • Subclass accepts such message sequences that the super class does not
    • Direct access to super class instance variables

32

Object-oriented Testing

Shape move()

Circle resize()

Square resize()

Ellipse resize()

Q: What if implementation of resize() for each subclass calls inherited operation move()? A: Shape cannot be completely tested unless we also test Circle, Square, and Ellipse.

33

  • Polymorphism
    • Polymorphism is a very powerful and expressive program technique. It may make the code shorter and easier to read.
    • Dynamic binding is the run-time implementation of the polymorph structures.
    • A reference to a super class can be bound to any subclass instance.
    • Replace explicit compile-time binding and static type checking by implicit binding and run-time type checking.

34

Object-oriented Testing

• Polymorphism

  • Polymorph servers has to be tested with each

subclass instance that it can accept.

  • Using polymorph structures does not decrease

the possibility of bugs. In fact it might even

increase it.

  • Bug hazard in the subclass instance given to

polymorph server are similar to those described

in case of inheritance related bugs.

37

Conclusion

• Some bugs typical of procedural languages

can be avoided by its correct usage.

• Encapsulation, inheritance and

polymorphism introduce the test designers

new concerns.

• There are changes in testing strategies.