Testing Object-Oriented Programs

Slides:



Advertisements
Similar presentations
Test Yaodong Bi.
Advertisements

Unit Testing in the OO Context(Chapter 19-Roger P)
When is Orientated Programming NOT? Mike Fitzpatrick.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Transition from C to C++ …and a Review of Basic Problem Solving.
Chapter 7 Testing Class Hierarchies. SWE 415 Chapter 7 2 Reading Assignment  John McGregor and David A. Sykes, A Practical Guide to Testing Object-Oriented.
Unified Modeling Language
Systems development life cycle & development methodologies
Introduction To System Analysis and Design
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
1 Software Testing and Quality Assurance Lecture 21 – Class Testing Basics (Chapter 5, A Practical Guide to Testing Object- Oriented Software)
Programming Language Paradigms: summary. Object-oriented programming Objects are the fundamental building blocks of a program. Interaction is structured.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. slide 1 CS 125 Introduction to Computers and Object- Oriented Programming.
SOS OOP Fall 2001 Object Oriented Programming in Java Week 1 Read a design Design a small program Extract a design Run a VAJ program Change that program,
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
Introduction To System Analysis and design
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
Systems Analysis and Design in a Changing World, Fifth Edition
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
1 Object-Oriented Testing CIS 375 Bruce R. Maxim UM-Dearborn.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Object-Oriented Software Testing. C-S 5462 Object-Oriented Software Testing Research confirms that testing methods proposed for procedural approach are.
BCS 2143 Introduction to Object Oriented and Software Development.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Unified Modeling Language, Version 2.0
Introduction To System Analysis and Design
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
1 Life Cycle of Software Specification Design –Risk Analysis –Verification Coding Testing –Refining –Production Maintenance.
Systems Analysis and Design in a Changing World, 3rd Edition
Software Construction Lecture 18 Software Testing.
Information System Design (IT60105) Lecture 26 Object-Oriented System Testing.
1 Testing Object- Oriented Programs CS 4311 J. McGregor and D. Sykes. A Practical Guide to Testing Object-Oriented Software, Addison-Wesley, I. Burnstein.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CONTENT 1.Software Process 2.Object Technology 3.UML 4.UML For Java.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Chapter 3: Introducing the UML
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
OBJECT-ORIENTED TESTING. TESTING OOA AND OOD MODELS Analysis and design models cannot be tested in the conventional sense. However, formal technical reviews.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
1 Design Object Oriented Solutions Object Oriented Analysis & Design Lecturer: Mr. Mohammed Elhajj
1 if you use this format with a picture in the vertical- stripe format, then adjust the RH edge of the title bar to be just L of the stripe. Test Automation.
Slide 1 Unified Modeling Language, Version 2.0 Object-Oriented SAD.
Principles of Programming & Software Engineering
CSC 222: Object-Oriented Programming
CSE 219 Final exam review.
Cmpe 589 Spring 2006.
Object-oriented software testing
Inheritance and Polymorphism
Chapter 11 Object-Oriented Design
Data Abstraction: The Walls
Principles of Programming and Software Engineering
Object-Orientated Programming
Chapter 24 Testing Object-Oriented Applications
Chapter 19 Testing Object-Oriented Applications
Software Design Lecture : 14.
Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract, Computer,
Chapter 13: Construction
Chapter 19 Testing Object-Oriented Applications
COP 3330 Object-oriented Programming in C++
Chapter 2. Problem Solving and Software Engineering
TYPES OF TESTING.
Presentation transcript:

Testing Object-Oriented Programs CS 4311 J. McGregor and D. Sykes. A Practical Guide to Testing Object-Oriented Software, Addison-Wesley, 2001. I. Burnstein. Practical Software Testing, Springer-Verlag, 2003. 1 1

Outline OO testing, why different? Class as unit Test harness Testing class hierarchies

What’s Different about Testing OO Programs? Encapsulation Polymorphism Inheritance Development

Unit Testing OO Programs Definition A unit is the smallest possible testable software component, e.g., function, procedure, or module. What’s unit in OO? Method vs. class

Method As Unit Methods tend to be small and less meaningful in isolation Impossible to test some methods (e.g., private methods) Overhead to test each method separately

Class As Unit Purpose Approach Test a class as a whole Emphasizes interactions among methods Approach Test critical methods individually Test interactions among methods Test sequences of methods calls, e.g., pop after push

Testing Interactions Why test interactions? Intra-class interactions An OOP is a collection of objects collaborating to solve some problem. The correct collaboration (or interaction) is critical to the correctness of the program. Intra-class interactions E.g., pop after push Inter-class interactions (integration test) Test sequences of messages among collaborating objects. Can use message sequence diagrams, collaboration diagrams, and use case scenarios to generate test cases.

Describing Test Cases Conventional definition In OO A pair of inputs and the expected output, xi, o In OO Need to specify the receiver (often called object under test) and its state too, e.g., r in r.m(x1, x2, …, xn) Thus, it is a tuple of rpre, xi, rpost, o, e, where r : is the object under test rpre : the receiver r’s state in the pre-state xi : a list of arguments rpost : the receiver r’s state in the post-state o: expected return value e: expected exception

Example A test case for testing the method “void setX(int)” of the class Point with the instance fields x and y, e.g., Point r = new Point(10,10); r.setX(20); Input Output receiver (r) args (x) receiver (r) return-value exception r.x = 10 x = 20 r.x = 20 none none r.y = 10 r.y = 10

Constructing Test Cases Testing individual methods Black-box test and white-box test Testing interactions Random testing State-based approach Can use state diagrams to generate sequences of method calls Testing exceptions Design-by-Contract (DBC) vs. defensive design

Outline OO testing, why different? Class as unit Test harness Testing class hierarchies

Test Harness A test harness is the auxiliary code developed to support testing of units and components, consisting of: Drivers that call the target code, and Stubs that represents modules it calls. driver call result unit under test call ack call ack stub1 stubn

Constructing Test Harness Conditionally compiled Test code closely maintained with class code (e.g., in the same file) Hard to reuse (e.g., to test a subclass) Requires support for conditional compilation As static methods or nested classes Test code closely maintained with class code Easy to reuse (e.g., by inheritance) Need to strip down test code before product delivery As separate tester class

Separate Test Class Strengths Weaknesses Guideline Easy to reuse (e.g., to test a subclass) Small and fast production code Weaknesses Need to create a new tester class Need to manage changes carefully Guideline Use unit testing frameworks such as JUnit for Java, CppUnit for C++, and NUnit of C#. Tester CTester C

Outline OO testing, why different? Class as unit Test harness Testing class hierarchies

Testing Class Hierarchies If a new class D is added, what methods need to be tested? Need test bar() of D? What about inherited methods, e.g., foo()? Can use existing test cases of C? What if D adds a new method? C foo() bar() D

Organizing Testing Harness Parallel architecture for class testing (PACT) Use inheritance to organize test cases and test classes Tester CTester C DTester D

Testing Abstract Classes Can you test abstract classes? Approaches