Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt www.introsoftwaretesting.com.

Slides:



Advertisements
Similar presentations
Mutation Testing. Mutation testing is a fault-based testing technique. It has been empirically and theoretically validated that a program will be well.
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Software Testing Chapter 5.2 Program-based Grammars Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 9.4 Model-Based Grammars Paul Ammann & Jeff Offutt
Chapter 12: Adding Functionality to Your Classes.
Chapter 8 More Object Concepts
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Writing Classes (Chapter 4)
Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Inheritance in the Java programming language J. W. Rider.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Introduction to Software Testing Chapter 9.3 Integration and Object- Oriented Testing Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.1 Syntax-based Testing Paul Ammann & Jeff Offutt
Syntax-Based Testing Mingzhe Du Hongying Du Dharani Chintapatla.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Software Testing Integration and Object-Oriented Testing.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to Software Testing (2nd edition) Chapter 7.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Introduction to Software Testing Chapter 9.2 Program-based Grammars Paul Ammann & Jeff Offutt
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Software Testing and Quality Assurance Syntax-Based Testing (2) 1.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Paul Ammann & Jeff Offutt
Inheritance ITI1121 Nour El Kadri.
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Inheritance and Polymorphism
Chapter 3: Using Methods, Classes, and Objects
Types of Programming Languages
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Overloading and Constructors
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.2 Program-based Grammars
Java Programming, Second Edition
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
An Analysis of OO Mutation Operators Jingyu Hu, Nan Li, and Jeff Offutt Presented by Nan Li 03/24/2011.
Presentation transcript:

Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt

© Ammann & Offutt 2 Integration and Object-Oriented Testing In Java, testing the way classes, packages and components are connected –“Component” is used as a generic term This tests features that are unique to object-oriented programming languages –inheritance, polymorphism and dynamic binding Integration testing is often based on couplings – the explicit and implicit relationships among software components Integration Testing Testing connections among separate program units Introduction to Software Testing (Ch 5),

© Ammann & Offutt 3 Instantiating Grammar-Based Testing Grammar-Based Testing Program-basedIntegrationModel-BasedInput-Based Compiler testing Valid and invalid strings Grammar String mutation Program mutation Valid strings Mutants are not tests Must kill mutants Input validation testing XML and others Valid strings Grammar Test how classes interact Valid strings Mutants are not tests Must kill mutants Includes OO String mutation FSMs Model checking Valid strings Traces are tests String mutation Input validation testing XML and others Invalid strings No ground strings Mutants are tests String mutation 5.3 Introduction to Software Testing (Ch 5),

© Ammann & Offutt 4 Grammar Integration Testing (5.3.1) There is no known use of testing at the integration level There is no known use of grammar testing at the integration level Introduction to Software Testing (Ch 5),

© Ammann & Offutt 5 Integration Mutation (5.3.2) Faults related to component integration often depend on a mismatch of assumptions –Callee thought a list was sorted, caller did not –Callee thought all fields were initialized, caller only initialized some of the fields –Caller sent values in kilometers, callee thought they were miles Integration mutation focuses on mutating the connections between components –Sometimes called “interface mutation” –Both caller and callee methods are considered Introduction to Software Testing (Ch 5),

© Ammann & Offutt 6 Four Types of Mutation Operators Change a calling method by modifying values that are sent to a called method Change a calling method by modifying the call Change a called method by modifying values that enter and leave a method –Includes parameters as well as variables from higher scopes (class level, package, public, etc.) Change a called method by modifying return statements from the method Introduction to Software Testing (Ch 5),

© Ammann & Offutt 7 Five Integration Mutation Operators Each parameter in a method call is replaced by each other variable in the scope of the method call that is of compatible type. 1. IPVR –– Integration Parameter Variable Replacement This operator replaces primitive type variables as well as objects. Each expression in a method call is modified by inserting all possible unary operators in front and behind it. 2. IUOI –– Integration Unary Operator Insertion The unary operators vary by language and type Each parameter in a method call is exchanged with each parameter of compatible types in that method call. 3. IPEX –– Integration Parameter Exchange max (a, b) is mutated to max (b, a) Introduction to Software Testing (Ch 5),

© Ammann & Offutt 8 Five Integration Mutation Operators (2) Each method call is deleted. If the method returns a value and it is used in an expression, the method call is replaced with an appropriate constant value. 4. IMCD –– Integration Method Call Deletion Method calls that return objects are replaced with calls to “new ()” Each expression in each return statement in a method is modified by applying the UOI and AOR operators. 5. IREM –– Integration Return Expression Modification Introduction to Software Testing (Ch 5),

© Ammann & Offutt 9 Object-Oriented Mutation These five operators can be applied to non-OO languages –C, Pascal, Ada, Fortran, … They do not support object oriented features –Inheritance, polymorphism, dynamic binding Two other language features that are often lumped with OO features are information hiding (encapsulation) and overloading Even experienced programmers often get encapsulation and access control wrong Testing Levels intra-method inter-method intra-class inter-class integration mutation operators Introduction to Software Testing (Ch 5),

© Ammann & Offutt 10 Encapsulation, Information Hiding and Access Control Encapsulation : An abstraction mechanism to implement information hiding, which is a design technique that attempts to protect parts of the design from parts of the implementation –Objects can restrict access to their member variables and methods Java provides four access levels (C++ & C# are similar) –private –protected –public –default (also called package) Often not used correctly or understood, especially for programmers who are not well educated in design Introduction to Software Testing (Ch 5),

© Ammann & Offutt 11 Access Control in Java SpecifierSame class Same package Different package subclass Different package non-subclass private package protected public YYYYYYYY nYYYnYYY nnYYnnYY nnnYnnnY Most class variables should be private Public variables should seldom be used Protected variables are particularly dangerous – future programmers can accidentally override (by using the same name) or accidentally use (by mis-typing a similar name) –They should be called “unprotected” Introduction to Software Testing (Ch 5),

© Ammann & Offutt 12 Class 4 Access Control in Java (2) Class 1 inheritance Class 3Class 2 Package Class 5 private membersdefaultprotected memberspublic members Introduction to Software Testing (Ch 5),

© Ammann & Offutt 13 Object-Oriented Language Features (Java) Method overriding Allows a method in a subclass to have the same name, arguments and result type as a method in its parent Variable hiding Achieved by defining a variable in a child class that has the same name and type of an inherited variable Class constructors Not inherited in the same way other methods are – must be explicitly called Each object has … –a declared type : Parent P; –an actual type : P = new Child (); or assignment : P = Pold; –Declared and actual types allow uses of the same name to reference different variables with different types Introduction to Software Testing (Ch 5),

© Ammann & Offutt 14 OO Language Feature Terms Polymorphic attribute –An object reference that can take on various types –Type the object reference takes on during execution can change Polymorphic method –Can accept parameters of different types because it has a parameter that is declared of type Object Overloading –Using the same name for different constructors or methods in the same class Overriding –A child class declares an object or method with a name that is already declared in an ancestor class –Easily confused with overloading because the two mechanisms have similar names and semantics –Overloading is in the same class, overriding is between a class and a descendant Introduction to Software Testing (Ch 5),

© Ammann & Offutt 15 More OO Language Feature Terms Members associated with a class are called class or instance variables and methods –Static methods can operate only on static variables; not instance variables –Instance variables are declared at the class level and are available to objects 29 object-oriented mutation operators defined for Java – muJava Broken into 4 general categories Introduction to Software Testing (Ch 5),

© Ammann & Offutt 16 Class Mutation Operators for Java (1) Encapsulation (2) Inheritance (3) Polymorphism (4) Java-Specific AMC IHI, IHD, IOD, IOP, IOR, ISI, ISD, IPC PNC, PMD, PPD, PCI, PCD, PCC, PRV, OMR, OMD, OAC JTI, JTD, JSI, JSD, JID, JDC, EOA, EOC, EAM, EMM Introduction to Software Testing (Ch 5),

© Ammann & Offutt 17 OO Mutation Operators—Encapsulation The access level for each instance variable and method is changed to other access levels. 1. AMC –– Access Modifier Change Introduction to Software Testing (Ch 5),

© Ammann & Offutt 18 OO Mutation Operators—Example 1. AMC – Access Modifier Change point private int x;  1 public int x;  2 protected int x;  3 int x; Introduction to Software Testing (Ch 5),

© Ammann & Offutt 19 OO Mutation Operators—Inheritance Each declaration of an overriding or hiding variable is deleted. 3. IHD –– Hiding Variable Deletion A declaration is added to hide the declaration of each variable declared in an ancestor. 2. IHI –– Hiding Variable Insertion Each entire declaration of an overriding method is deleted. 4. IOD –– Overriding Method Deletion Each call to an overridden method is moved to the first and last statements of the method and up and down one statement. 5. IOP –– Overriding Method Calling Position Change Introduction to Software Testing (Ch 5),

© Ammann & Offutt 20 OO Mutation Operators—Example 2. IHI – Hiding Variable Insertion colorpoint  1 int x;  2 int y; point int x; int y; 3. IHD – Hiding Variable Deletion point int x; int y; colorpoint int x;  1 // int x; int y;  2 // int y; Introduction to Software Testing (Ch 5),

© Ammann & Offutt 21 OO Mutation Operators—Example 4. IOD – Overriding Method Deletion 5. IOP – Overriding Method Calling Position Change point void set (int x, int y) colorpoint void set (int x, int y)  // void set (int x, int y) point void set (int x, int y) { width = 5;…} colorpoint void set (int x, int y) { super.set (x, y); width = 10;}  { width=10; super.set (x, y); } Introduction to Software Testing (Ch 5),

© Ammann & Offutt 22 OO Mutation Operators—Inheritance Insert the keyword super in front of each overriding method or variable. 7. ISI –– Super Keyword Insertion Delete each occurrence of the super keyword. 8. ISD –– Super Keyword Deletion Each call to a super constructor is deleted. 9. IPC –– Explicit Call of a Parent's Constructor Deletion Renames the parent's versions of methods that are overridden in a subclass so that the overriding does not affect the parent's method. 6. IOR –– Overriding Method Rename Introduction to Software Testing (Ch 5),

© Ammann & Offutt 23 OO Mutation Operators—Example 6. IOR – Overriding Method Rename point … void set (int x, int y)  void setP (int x, int y) … void setDimension (int d) { … set (x, y);  setP (x, y); … } colorpoint … void set (int x, int y) point p; p = new colorpoint (); … p.Set (1, 2); p.setDimension (3); 7. ISI – Super keyword Insertion colorpoint int getX () { return x;  return super.x; } point int getX () Introduction to Software Testing (Ch 5),

© Ammann & Offutt 24 OO Mutation Operators—Example 8. ISD – Super keyword Deletion9. IPC – Explicit Call of a Parent’s Constructor Deletion point int getX() colorpoint int getX () { return super.x;  return x; } point point (int x, int y) … colorpoint colorpoint (int x, int y, int color) { super (x, y);  // super (x, y); … } Introduction to Software Testing (Ch 5),

© Ammann & Offutt 25 Changes the declared type of a parameter object reference to be the parent of its original declared type. 12. PPD –– Parameter Variable Declaration With Child Class Type OO Mutation Operators—Polymorphism An object’s actual type is changed to a child of the original actual type in the new() statement. 10. PNC –– New Method Call With Child Class Type Change the actual type of an object reference to the parent or to the child of the declared type. 13. PCI –– Type Cast Operator Insertion An object’s declared type is changed to the parent of the original actual type in the declaration statement. 11. PMD –– Member Variable Declaration With Parent Class Type Introduction to Software Testing (Ch 5),

© Ammann & Offutt 26 OO Mutation Operators—Example 10. PNC – New Method Call with Child Class Type 11. PMD – Member Variable Declaration with Parent Class Type point point p; p = new point ();  p = new colorpoint (); colorpoint point colorpoint point p; p = new colorpoint ();  p = new point (); Introduction to Software Testing (Ch 5),

© Ammann & Offutt 27 OO Mutation Operators—Example 12. PPD – Parameter Variable Declaration with Child Class Type 13. PCI – Type Case Operator Insertion point boolean equals (point p) {... }  boolean equals (colorpointp) {...} colorpoint point colorpoint colorpoint pc; point p = cp; p.getX();  ((colorpoint) p).getX(); Introduction to Software Testing (Ch 5),

© Ammann & Offutt 28 OO Mutation Operators—Polymorphism Delete a type casting operator 14. PCD –– Type Cast Operator Deletion Change the type to which an object reference is being cast 15. PCC –– Cast Type Change Changes operands of reference assignments to be assigned to objects of subclasses. 16. PRV –– Reference Assignment With Other Comparable Variable For each pair of methods that have the same name, the bodies are interchanged. 17. OMR –– Overloading Method Contents Replace Introduction to Software Testing (Ch 5),

© Ammann & Offutt 29 OO Mutation Operators—Example 15. PCC – Cast Type Change point colorpoint pc; point p = cp; ((colorpoint) p).getX();  p.getX(); colorpoint point colorpoint ((point p).getX();  ((colorpoint) p).getX(); 14. PCD – Type Case Operator Deletion Introduction to Software Testing (Ch 5),

© Ammann & Offutt 30 OO Mutation Operators—Example 17. OMR – Overloading Method Contents Replace 16. PRV – Reference Assignment with Other Comparable Variable point p; colorpoint cp = new colorpoint(0, 0); point3D p3d = new point3D(0, 0, 0); p = cp;  p = p3d; point colorpointpoint3D point point3D … void set (int x, int y) { S1 } void set (int x, int y, int z) { S2 }  // void set (int x, int y, int z) { S1 } Introduction to Software Testing (Ch 5),

© Ammann & Offutt 31 OO Mutation Operators—Polymorphism Each overloaded method declaration is deleted, one at a time. 18. OMD –– Overloading Method Deletion Changes the number and order of arguments in method invocations, but only if there is an overloading method that can accept the new argument list. 19. OAC –– Arguments Of Overloading Method Call Change Introduction to Software Testing (Ch 5),

© Ammann & Offutt 32 OO Mutation Operators—Example 19. OAC – Arguments of Overloading Method Call Change 18. OMD – Overloading Method Deletion point point3D … void set (int x, int y) { …}  // void set (int x, int y) { …} void set (int x, int y, int z) { … } point3D p; p.set (1, 2, 3);  p.set (1, 3, 2);  p.set (2, 3);  p.set (3); point point3D void set (int x, int y, int z); void set (int x, int y); void set (int z); Introduction to Software Testing (Ch 5),

© Ammann & Offutt 33 OO Mutation Operators—Language Specific The keyword this is added when appropriate. 20. JTI –– This Keyword Insertion Each occurrence of the keyword this is deleted. 21. JTD –– This Keyword Deletion The static modifier is added to instance variables. 22. JSI –– Static Modifier Insertion Each instance of the static modifier is removed. 23. JSD –– Static Modifier Deletion Introduction to Software Testing (Ch 5),

© Ammann & Offutt 34 OO Mutation Operators—Example 21. JTD – This Keyword Deletion20. JTI – This Keyword Insertion point … void set (int x, int y) { this.x = x;  this.x = this.x; this.y = y;  this.y = this.y; } … point … void set (int x, int y) { this.x = x;  x = x; this.y = y;  y = y; } … Introduction to Software Testing (Ch 5),

© Ammann & Offutt 35 OO Mutation Operators—Example 23. JSD – Static Modifier Deletion22. JSI – Static Modifier Insertion point public int x = 0;  public static int x = 0; … point public static int x = 0;  public int x = 0; … Introduction to Software Testing (Ch 5),

© Ammann & Offutt 36 OO Mutation Operators—Language Specific Remove initialization of each member variable. 24. JID –– Member Variable Initialization Deletion Remove the implemented default constructor, forcing Java to create a default constructor. 25. JDC –– Java-supported Default Constructor Creation Replaces the right hand side of an object assignment with an assignment of a clone of the object. 26. EOA –– Reference Assignment and Content Assignment Replacement Replaces a comparison of two objects using the “==“ operator with the “equals()” method. 27. EOC –– Reference Comparison and Content Comparison Replacement Introduction to Software Testing (Ch 5),

© Ammann & Offutt 37 OO Mutation Operators—Example 25. JDC – Java-supported Default Constructor Creation 24. JID – Member Variable Initialization Deletion point int x = 0;  int x; … point point() { … }  // point() { … } … Introduction to Software Testing (Ch 5),

© Ammann & Offutt 38 OO Mutation Operators—Example 27. EOC – Reference Comparison and Content Comparison Replacement 26. EOA – Reference Assignment and Content Assignment Replacement point p1, p2; p1 = new point (1, 2); p2 = p1;  p2 = p1.clone(); point p1 = new point (1, 2); point p2 = new point (1, 2); … if (p1 == p2)  if (p1.equals (p2)) { … } Introduction to Software Testing (Ch 5),

© Ammann & Offutt 39 Replaces calls to “ setter ” methods ( setX() ) with calls to other compatible getter methods ( setY() ). 29. EMM –– Modifier Method Change OO Mutation Operators—Language Specific Replaces calls to “ getter ” methods ( getX() ) with calls to other compatible getter methods ( getY() ). 28. EAM –– Acessor Method Change Introduction to Software Testing (Ch 5),

© Ammann & Offutt 40 OO Mutation Operators—Example 29. EMM – Modifier Method Change point p1 = new point (1, 2); … p1.getX();  p1.getY(); point p1 = new point (1, 2); … p1.setX(4);  p1.setY(4); 28. EAM – Accessor Method Change point … public int getX () { … } public int getY () { … } public void setX (int x){ … } public void setY (int y){ … } … point … public int getX () { … } public int getY () { … } public void setX (int x) { … } public void setY (int y){ … } … Introduction to Software Testing (Ch 5),

© Ammann & Offutt 41 Integration Mutation Summary Integration testing often looks at couplings We have not used grammar testing at the integration level Mutation testing modifies callers and callees OO mutation focuses on inheritance, polymorphism, dynamic binding, information hiding and overloading –The access levels make it easy to make mistakes in OO software muJava is an educational / research tool for mutation testing of Java programs – Introduction to Software Testing (Ch 5),