50
1 Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung The University of Texas at Arlington and Advanced Software International Corporation Arlington, Texas 76019-0015 817-272-3785 [email protected]

Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

  • Upload
    ula

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung The University of Texas at Arlington and Advanced Software International Corporation Arlington, Texas 76019-0015 817-272-3785 [email protected]. Overview of Presentation. - PowerPoint PPT Presentation

Citation preview

Page 1: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

1

Testing Object-Oriented Software

A Presentation at a DFW ASEE Meeting

Dr. David C. KungThe University of Texas at Arlington

andAdvanced Software International Corporation

Arlington, Texas 76019-0015817-272-3785

[email protected]

Page 2: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

2

Overview of Presentation

• Why Object-Oriented Software Testing• The State-of-the-Research• OO Software Testing Research at UTA• OOTWorks Software Demonstration

Page 3: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

3

Why Object-Oriented Software Testing

• transition to OO development is not easy– OO conceptualization, design and programming

significantly impact the quality

– many developers’ mindset is still in procedural design and programming

– anti-design patterns are commonly found in OO design and OO code

Page 4: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

4

Case Study 1: Analysis of a Fedex Ship Manager Software

• This software was designed and implemented by a team of students taking an OO software engineering class

• It has nothing to do with Fedex

• The software was supposed to compute and display the shipment charges for all Fedex services from a given origin zip to a given destination zip

• This program is working but it has some design problems

• We show how OOTWorks can be used to detect these design problems

Page 5: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

5

Poor Conceptualization

NextAfternoon,OvernightExpress,Ground, etc. are services. They are not a RateChart.

It is better to use association.

Page 6: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

6

Poor Responsibility Assignment

There should not be a class called “RateCalculator”. The services are the “experts” who know how to calculate their own rates.

This design assigns the responsibility to the wrong object.

Page 7: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

7

Incorrect Use of Inheritance

Child classes must not repeat the same code as the parent class, failing to utilize the inheritance and polymorphism features. This increases the maintenance effort.

Page 8: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

8

Better Design

Better conceptualization.

The services use ZoneChart and Delivery Area Surcharge to calculate rates.

Page 9: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

9

Better Design

The subclasses inherit and use all of the methods of the superclass.

Page 10: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

10

Automatic Design Improvement The repeated code can be deleted from the subclasses.

Page 11: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

11

Automatic Design Improvement

Page 12: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

12

Why Object-Oriented Software Testing

• OO features introduce new testing problems– encapsulation leading to long method invocation

chains, more difficulty to understand the (overall) functionality

– inheritance and polymorphism: which method to execute is determined at run time

– multiple and/or repeated inheritance may cause incorrect interaction in child classes

– you cannot test a class, you can only test instances of a class

Page 13: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

13

0

100

200

300

400

500

600

700

800

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Invocation chains in the InterViews Library: 122 classes, >400 relationships

Chain Length

Num

ber

of C

hain

s

Page 14: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

14

Why Object-Oriented Software Testing

main () { Shape *p; …. p->print(); // which print() to // execute? … }

Shapeprint ()

Boxprint ()

Squareprint ()

Page 15: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

15

• objects engage in complex interdependent relationships– testing one object may require test stubs to simulate

other objects

– test stubs construction is costly and time consuming

– mutual or cyclic dependencies introduce additional complexity and costs in unit and integration testing

– need a test order for unit testing and integration testing

Why Object-Oriented Software Testing

Page 16: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

16

Complex Relationships

Page 17: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

17

• objects exhibit strong state dependent behaviors– how to identify states and transitions?

– how to identify state dependent interactions?

– how to generate test cases to test state behaviors?

– how to reduce the complexity of state behavior testing?

Why Object-Oriented Software Testing

Page 18: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

18

The State-of-the-Research

• OO software testing began in the 1990s• A number of test methods and techniques have

been proposed• There are various tools, some are free some are

not• The tester still has to do a lot of work

Page 19: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

19

The State-of-the-Research

• OO Test Methods and Techniques– incremental testing of class hierarchy

– test order

– object state testing

– class testing, cluster testing

– data flow analysis

– testing polymorphic relationships

– data flow analysis for exception handling mechanism

– OO regression testing

Page 20: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

20

OO Software Testing Research at UTA

• A reverse engineering technology• Plus a set of utilities to facilitate

• program understanding• design documentation • design analysis• design improvement • metrics calculation• test scheduling• change impact analysis• version comparison

• test case generation• test data generation • design improvement• code review & analysis• code improvement• test execution• result analysis• and more ...

• The result is the OOTWorks toolkit

Page 21: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

21

Why OOTWorks

• It improves productivity and quality in– Documentation

– Design and code reviews

– Testing, regression testing and maintenance

– Test planning and scheduling

• It reduces the time and effort required to prepare for CMM/ audit each year

Page 22: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

22

The OOTWorks Modules

ORD(Object Relation Diagram)

BBD

(Block Bench Diagram)

OSD(Object State Diagram) (Package Relation Diagram)

PRD

OID(Object Interaction Diagram)

Page 23: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

23

Object Relation Diagram (ORD)

• Visualization of– Classes, relationships, data members, function members,

and source code, selectable by the user

– Test order for unit and integration testing

– Change impact and version comparison

• Computation of various OO metrics• Useful for

– program comprehension and assessment

– documentation

– design and code review

– test scheduling and effort estimation

Page 24: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

24

An Object Relation Diagram

Page 25: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

25

Object Relation Diagram (ORD)

• Generation of a cost-effective schedule – for implementing the classes (required code skeleton)

– for changing the classes

– for code review of the classes

– for testing the classes

– it effectively reduces time, effort and costs to accomplish above tasks

Page 26: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

26

Generation of Cost-Effective Test Order

Classes with test order 1:0 should be tested before classes with test order 2:0 to reduce the test effort.

Page 27: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

27

Test Stubs Required for Randomly Selected Test Sequences

Page 28: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

28

Saving from Test Order

• Average one person-hour is required to construct a test stub.

• For the InterViews library, 191.88 person-hours, or close to 5 person-weeks are required.

• Using test order, only one test stub is needed, the saving in effort and costs are tremendous even for this small program.

Page 29: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

29

Generation of Test Schedule

Critical path

Testing of classes on the critical path must be completed on time to ensure that the test process will be completed on time.

Page 30: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

30

Object Relation Diagram (ORD)

• Computation of various OO metrics– Fan-in and fan out

– Depth of inheritance tree

– Number of lines of code

– Length of invocation chain

– Cyclomatic complexity

– Number of children, etc.

• Useful for assessing program quality and spot potential problem areas

Page 31: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

31

Various OO Metrics

Page 32: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

32

Object Relation Diagram (ORD)

• Change impact analysis and visualization– Compare change alternatives

• Version comparison and visualization– Compare two versions/releases to identify changes and

their impact

– Visualizing the two versions/releases to facilitate code review and inspection to ensure that changes are made properly

– Useful for maintenance, release review and regression testing to reduce time, effort and costs

Page 33: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

33

Change and Impact Analysis

Page 34: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

34

Block Branch Diagram (BBD)

Page 35: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

35

Block Branch Diagram (BBD)

for test input preparation

for test case preparation

for test stub preparation

Page 36: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

36

An Overly Complex Method Is Difficulty to Comprehend and Test

Page 37: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

37

Block Branch Diagram

• Useful for white-box testing (basis path, data flow)

• Useful for state transition construction

• Useful for black-box testing

– Boundary value analysis

– Functional testing

• Initialize parameters

• Initialize input values

• Identify and construct test stubs

• Analysis of test results (changed variables)

• Used for sequence diagram reverse engineering

Page 38: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

38

Object State Diagram

• Hierarchical, concurrent, communicating state machines

• Generated from C++/Java source code using a reverse engineering approach

• Represents the dynamic state dependent behavior of objects

Page 39: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

39

allowVend: unsigned

0,0

0,0 1,M

1,M

CoinBox()

CoinBox()

Reset()

Reset() Vend()

AddQtr()

[curQtrs > 0]AddQtr()

AddQtr()

ReturnQtrs()[allowVend !=0] Vend()

S0 S1

S0 S1

curQtrs: unsigned

An Object State Diagram for an incorrect coin box class

Page 40: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

40

(S0, S0)

(S0, S0)

(S0, S0)

(S0, S0)

(S1, S1)

(S1, S1)

(S0, S1)

(S1, S1)

(S1, S0)

Reset(), ReturnQtr()

Reset(), ReturnQtr()

ReturnQtr()AddQtr()

AddQtr()

AddQtr()

Reset()

(S0, S0) (S1, S0)

ReturnQtr()Reset()AddQtr()Vend()

Vend()

Test tree showing the execution sequences of a COSD

Page 41: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

41

off, off, off

heat,off,off cool,off,off

off, off, off

SS, FR, AR

SS.heat SS.cool

heat, on, off off, off, off

off, on, off

off, off, offcool, on, offheat, on, off

off, on, off cool, on, on

SS.offFR.turnOn SS.off

SS.off

SS.heat

SS.cool

FR.turnOff

SS.off AR.turnOnSS: Season SwitchFR: Furnace RelayAR: A/C Relay

Test tree showing a flaw in a thermostat system.

Page 42: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

42

Sequence Diagram

• A sequence diagram describes the object interaction through time ordered message passing.

• Elements and their Notations– Objects

• Placed at top of the diagram across the horizontal axis

– Lifelines • Dotted lines extending down the vertical axis

– Messages and Stimulus• Horizontal solid labeled arrow.

– Focus of Control• Tall thin rectangle along the vertical axis.

Page 43: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

43

Sequence Diagram Example

Page 44: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

44

Sequence Diagram Showing a Use Case

Page 45: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

45

Usefulness of Sequence Diagram

• Understanding how use cases are implemented• Automatic generation of test cases and test data to

test the implementation• Facilitating design and code review• Check if some behavioral design patterns are

propertly implemented

Page 46: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

46

Some Application Data

• OOTWorks can process millions of lines of source code and thousands of classes

• Parsing of a 50,000 line C++ files finishes in 20 seconds

• Platform independent (Windows, Linux, Unix,Soloaris, Mac, etc.)

• Display and print very large ORD diagrams• Has been applied to real world applications with

satisfactory results

Page 47: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

47

Some Example Applications

– Identification of isolated classes

– Identification of possibly poorly designed OO software• no use of inheritance and/or aggregation

• only one parent class, all the other classes are direct children of the parent class

• classes with several thousand lines of code

• classes with very high fan-in and/or fan-out metrics

• high cyclomatic complexity

• classes having excessive number of methods may indicate poor cohesion (or too much responsibilities)

• etc.

Page 48: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

48

ORD

BBD

selected class &method

Functional Tests

Generation

Structural Tests

Generation

TestsTests

Execution

Result Analysis

Tester

using variablesused and changed

using basis paths &symbolic execution

interactivetesting

batchtesting

Possible Test Process

Page 49: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

49

ORD

OSD

selected classes

Method Sequence Tests Generation

Fault Analysis

TestsTests

Execution

Result Analysis

Tester

analysis results

Possible Test Process

Page 50: Testing Object-Oriented Software A Presentation at a DFW ASEE Meeting Dr. David C. Kung

50

Developer

Tester

SQA

Project Manager

• time, effort and cost control• productivity and quality improvement• test scheduling

• program understanding• documentation• verification• change impact analysis• metrics

• test order• program understanding• test cases and test data preparation• regression test• metrics

Maintenance

• version comparison• change impact analysis• regression test

• verification• design and code review• metrics• documentation

Summary