Introduction to Software Testing Chapter 5 3 Integration and Object Oriented Testing Paul Ammann Jeff Offutt www introsoftwaretesting com Integration and Object Oriented Testing Integration Testing Testing connections among separate program units 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 Introduction to Software Testing Ch 5 www introsoftwaretesting com Ammann Offutt 2 1 Instantiating Grammar Based Testing Grammar Based Testing 5 3 Program based Integration String mutation Grammar Program mutation Valid strings Mutants are not tests Must kill mutants Compiler testing Valid and invalid strings Model Based String mutation String mutation String mutation FSMs Model checking Valid strings Traces are tests Test how classes interact Valid strings Mutants are not tests Must kill mutants Includes OO Introduction to Software Testing Ch 5 www introsoftwaretesting com Input Based Grammar Input validation testing XML and others Invalid strings No ground strings Mutants are tests Input validation testing XML and others Valid strings Ammann Offutt 3 Grammar Integration Testing 5 3 1 There is no known use of grammar testing at the integration level Introduction to Software Testing Ch 5 www introsoftwaretesting com Ammann Offutt 4 2 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 www introsoftwaretesting com Ammann Offutt 5 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 www introsoftwaretesting com Ammann Offutt 6 3 Five Integration Mutation Operators 1 IPVR Integration Parameter Variable Replacement Each parameter in a method call is replaced by each other variable in the scope of the method call that is of compatible type This operator replaces primitive type variables as well as objects 2 IUOI Integration Unary Operator Insertion Each expression in a method call is modified by inserting all possible unary operators in front and behind it The unary operators vary by language and type 3 IPEX Integration Parameter Exchange Each parameter in a method call is exchanged with each parameter of compatible types in that method call max a b is mutated to max b a Introduction to Software Testing Ch 5 www introsoftwaretesting com Ammann Offutt 7 Five Integration Mutation Operators 2 4 IMCD Integration Method Call Deletion 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 Method calls that return objects are replaced with calls to new 5 IREM Integration Return Expression Modification Each expression in each return statement in a method is modified by applying the UOI and AOR operators Introduction to Software Testing Ch 5 www introsoftwaretesting com Ammann Offutt 8 4 Object Oriented Mutation Testing Levels intra method inter method intra class integration mutation operators inter class 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 Introduction to Software Testing Ch 5 www introsoftwaretesting com Ammann Offutt 9 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 www introsoftwaretesting com Ammann Offutt 10 5 Access Control in Java Specifier Same class private package protected public Same package Different package subclass Different package non subclass n Y Y Y n n Y Y n n n Y Y Y Y Y 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 www introsoftwaretesting com 11 Ammann Offutt Access Control in Java 2 Class 1 Package public members protected members Class 3 default private members inheritance Class 2 Class 5 Introduction to Software Testing Ch 5 www introsoftwaretesting com Class 4 Ammann Offutt 12 6 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 www introsoftwaretesting com Ammann Offutt 13 OO Language Feature Terms Polymorphic attribute An object reference that can take on various
View Full Document
Unlocking...