Testing Object-Oriented Software (an Overview) Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 12.

Slides:



Advertisements
Similar presentations
Defect testing Objectives
Advertisements

Unit Testing in the OO Context(Chapter 19-Roger P)
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
Software testing.
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Software Testing and Quality Assurance
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Chapter 1 Principles of Programming and Software Engineering.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
1 CS1001 Lecture Overview Object Oriented Design Object Oriented Design.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
C++ fundamentals.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 10 Slide 1 Formal Specification.
Chapter 13 & 14 Software Testing Strategies and Techniques
Testing Object Oriented Software Chapter 15. (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 2 Learning objectives Understand how object orientation.
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
System/Software Testing
These slides are designed to accompany Software Engineering: A Practitioner’s Approach, 7/e (McGraw-Hill 2009). Slides copyright 2009 by Roger Pressman.1.
1 Object-Oriented Testing CIS 375 Bruce R. Maxim UM-Dearborn.
Object-Oriented Software Testing. C-S 5462 Object-Oriented Software Testing Research confirms that testing methods proposed for procedural approach are.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Chapter 3 Introduction to Collections – Stacks Modified
程建群 博士(Dr. Jason Cheng) 年03月
Chapter 8 – Software Testing Lecture 1 1Chapter 8 Software testing The bearing of a child takes nine months, no matter how many women are assigned. Many.
INT-Evry (Masters IT– Soft Eng)IntegrationTesting.1 (OO) Integration Testing What: Integration testing is a phase of software testing in which.
Ch6: Software Verification. 1 Decision table based testing  Applicability:  Spec. is described by a decision table.  Tables describe:  How combinations.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 10 Use Case Design.
WXGE6103 Software Engineering Process and Practice Formal Specification.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Software Testing Yonsei University 2 nd Semester, 2014 Woo-Cheol Kim.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Requirements Engineering Methods for Requirements Engineering Lecture-30.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 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:
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
Chapter 8 Testing. Principles of Object-Oriented Testing Å Object-oriented systems are built out of two or more interrelated objects Å Determining the.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
CS451 Lecture 10: Software Testing Yugi Lee STB #555 (816)
Chapter 24 객체지향 응용프로그램 테스팅 Testing Object-Oriented Applications 임현승 강원대학교 Revised from the slides by Roger S. Pressman and Bruce R. Maxim for the book.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
1 Lecture 15: Chapter 19 Testing Object-Oriented Applications Slide Set to accompany Software Engineering: A Practitioner’s Approach, 7/e by Roger S. Pressman.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 4 Slide 1 Software Processes.
HNDIT23082 Lecture 09:Software Testing. Validations and Verification Validation and verification ( V & V ) is the name given to the checking and analysis.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
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 Programming and Data Abstraction Earl Huff Rowan University.
OBJECT-ORIENTED TESTING. TESTING OOA AND OOD MODELS Analysis and design models cannot be tested in the conventional sense. However, formal technical reviews.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
CSCE 240 – Intro to Software Engineering Lecture 3.
Defect testing Testing programs to establish the presence of system defects.
Principles of Programming and Software Engineering
Higher-Level Testing and Integration Testing
Software testing.
Chapter 10 – Software Testing
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Algebraic Specification Software Specification Lecture 34
Chapter 7 Software Testing.
Presentation transcript:

Testing Object-Oriented Software (an Overview) Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 12

Reference: Software Testing and Analysis: Process, Principles, and Techniques, by Michal Young and Mauro Pezze, John Wiley & Sons. (Other sources are readily identifiable via your favorite Internet search engine.)

Similarities and Differences The same basic pattern of testing procedural software… –using functional (black-box) tests supplemented by structural (white-box) tests, –working from the unit level toward the system level with one or more integration steps,...also applies to testing object-oriented software. (cont’d)

Similarities and Differences (cont’d) But some features of O-O languages require special strategies and/or considerations: –the inherently state dependent behavior of methods, –encapsulation of methods and state, –inheritance, and –polymorphism and dynamic binding. (cont’d)

Similarities and Differences (cont’d) We begin by summarizing the issue(s) and testing related considerations associated with each of these. Next, we present simple models for unit (object class) and integration (initial inter- object class) testing. Higher-level testing of object-oriented systems is basically similar to that of other systems, and is not considered further here.

State Dependent Behavior of Methods Method behavior may depend on both parameter values (“inputs”) and object state. For example, consider a linear “list” object class with Boolean inspection method “is_empty?”. The result – “true” or “false” – clearly depends on the state of “list”. (cont’d)

State Dependent Behavior of Methods (cont’d) Thus, test case design strategies that do not explicitly take state dependent program behavior into account must be modified to do so. Consider, for example, Input Space Partitioning and Cause-Effect Analysis. How might these approaches be modified to account for state- dependent program behavior? (cont’d)

State Dependent Behavior of Methods (cont’d) Ad-hoc modifications of these approaches are usually straightforward – especially when augmented with state machine models of program behavior. We’ll come back to this when considering object class testing...

Encapsulation of Methods and State Objects are comprised of both public and private attributes and methods. This is problematic when effects of operations are private and therefore “hidden” from the tester. The effect of method “append” on object class “list”, for example, may only be visible through a limited set of public attributes or “inspector operations.” (cont’d)

Encapsulation of Methods and State (cont’d) Special instrumentation may be required when methods result in hidden state changes, or are themselves private.

Inheritance Inheritance is an abstraction mechanism that allows classes to be specialized or extended from one or more other classes. A “child” class inherits attributes and methods from its ancestor classes, changing some, and adding others. (cont’d)

Inheritance (cont’d) A testing issue which arises involves deciding which methods in a derived class need to be (re-)tested. New methods obviously must be, as must changed methods unless it can be shown that their behavior will be unaffected. Unchanged methods which interact with changed or new methods may also need to be tested in the context of those interactions. (cont’d)

Inheritance (cont’d) In general, testers must determine when new tests must be designed, when old tests should be re-run, and when re-testing can be avoided all together.

Polymorphism and Dynamic Binding Many object-oriented languages allow variable types and method bindings to change dynamically. For example, when the generic elements of object class “list” are dynamically bound to particular data types, list operations such as “append(value)” will be bound to particular methods. (cont’d)

Polymorphism and Dynamic Binding (cont’d) Testers must be aware of the bindings that may occur, and systematically determine which methods (and which combinations of methods) to test.

Unit (Object Class) Testing

What are the “units” of O-O programs? “Unit testing” of O-O software often focuses on object classes as opposed to individual methods, as testing methods in isolation is not always practical since... –Method behavior can be obscured (due to encapsulation) when considered in isolation. –Methods often interact in altering object state.

State Machine Models State machine models are often useful for describing object class states and transitions. “States” can be inferred from descriptions of methods that act differently or return different results depending on the state of the object. (Consider Algebraic Specification axioms that incorporate conditionals.) Partitioning and combinatorial test case design techniques may be applied on a state-by-state basis.

A Simple Example Consider the operations for a generic Stack object: New – Bring a stack into existence Push – Add an element to the top of a stack Top – Evaluate the top element of a stack (without removing it) (cont’d)

A Simple Example (cont’d) Retract – Remove the top element from a stack and return the modified stack Is_Empty – True if and only if there are no elements on a stack (cont’d)

A Simple Example (cont’d) With method signatures: New -> Stack Push (Stack, Elem) -> Stack Top (Stack) -> Elem Retract (Stack) -> Stack Is_Empty (Stack) -> Boolean (cont’d)

A Simple Example (cont’d) Suppose the stack specification requires a storage capacity of N elements. How many different states would be required to represent every possible count of the elements stored? How might the states be partitioned into equivalence classes if the goal is to produce a simple model reflecting how state affects method behavior? (cont’d)

A Simple Example (cont’d) The Boolean inspection method “Is_Empty” suggests two important abstract states for modeling the state-dependent behavior of methods: empty and non-empty “Top” is usually not defined in state empty. “Retract” also acts differently depending on the state of the stack... (cont’d)

A Simple Example (cont’d) New emptynon-empty Push Retract Push State Machine Model (cont’d)

A Simple Example (cont’d) Test cases (sequences of method calls) should be designed which cover all transitions in the state machine model. State machine models are sometimes included in object-oriented program specifications. In the UML family of notations, they take the form of “state diagrams.”

Other object class testing strategies Functional test cases based on the state machine model should be augmented with structural tests derived from class source code. Special attention should be given to exception handling. Design additional tests for intra-class poly- morphic calls.

Integration (Initial Inter-Object Class) Testing

Object class integration Higher level O-O testing begins with the integration of (already unit-tested) object classes to form inter-object class functional entities. The primary objective of testing during this process is to discover interface and blatant higher-level design errors among the object classes being integrated. As with imperative software, integration should proceed incrementally. (cont’d)

Use/include relations Just as a calling hierarchy allows design of an integration strategy for imperative software, use/include relations serve this purpose for object-oriented software. Object classes A and B are related by a use/include relation if objects of class A make method calls on objects of class B, or if class A includes class B. Use/include relations may be derived from a conventional UML class diagram.

Incremental strategy Since there is generally no single “root” class, testing usually proceeds cluster by cluster in a “bottom-up” fashion, starting with “leaf” classes that depend on no others. The “brute force” approach of testing all combinations of calls and states while climbing use/include relations is impractical for most non-trivial systems. (cont’d)

Practical test coverage strategies Coverage strategies based on the (other, less conservative) combinatorial approaches considered previously are therefore more appropriate. Nominal interaction combinations may be identified from UML sequence or collaboration diagrams. Such diagrams can be thought of as test scenarios created during system design. (cont’d)

Practical test coverage strategies (cont’d) Unexpected or illegal interaction sequences should also be exercised to check error handling.

Scaffolding for O-O testing Both Unit (intra-class) and integration (inter- class) testing require drivers and stubs to exercise classes under test, and oracles to interpret/ inspect test results. Constructing drivers and stubs is similar to that for procedural software. Encapsulation of object state, however, can make the construction of oracles more difficult.

Oracles for Object Classes The result of executing a sequence of methods consists of both outputs produced and changes in object state. For example, if Top(Push(stack,Top(stack))) does not add a copy of the top-most element to the stack, the result is erroneous regardless of the output produced. (cont’d)

Oracles for Object Classes (cont’d) X Y Z Expected result of Top(Push(stack,Top(stack))) Output: State change: (cont’d)

Oracles for Object Classes (cont’d) Therefore, Oracles need to check the correctness of both output and state, but the state of objects may not be directly accessible. One solution: build oracles to subvert the encapsulation by modifying source code to allow inspection of private variables. If implemented, should such modifications be removed after testing, or left in the delivered code? (cont’d)

Oracles for Object Classes (cont’d) If modifications are removed, we risk differences in behavior between what is tested and what is used…e.g., –masked or introduced faults and/or –performance differences Modifications left in the code (or design rules requiring programmers to provide observability interfaces) avoid such discrepancies, but incur some overhead. (cont’d)

Oracles for Object Classes (cont’d) Ideally, the interface created for inspection of object state should be separated from the main class, as allowed, for example, by C++ “friend” classes †. An interface that produces a readable representation of object values is also useful in debugging as well as testing. † A friend class in C++ can access the “private” and “protected” members of the class in which it is declared as a friend.

Testing Object-Oriented Software (an Overview) Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 12