SlideShare a Scribd company logo
1 of 62
Testing Object Oriented Software
Chapter 15
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 2
Learning objectives
• Understand how object orientation impacts
software testing
– What characteristics matter? Why?
– What adaptations are needed?
• Understand basic techniques to cope with each key
characteristic
• Understand staging of unit and integration
testing for OO software (intra-class and inter-
class testing)
(c) 2008 Mauro Pezzè & Michal Young
Characteristics of OO Software
Typical OO software characteristics that impact
testing
• State dependent behavior
• Encapsulation
• Inheritance
• Polymorphism and dynamic binding
• Abstract and generic classes
• Exception handling
15.2
Ch 15, slide 3
(c) 2008 Mauro Pezzè & Michal Young
Quality activities and OO SW
Actual Needs and
Constraints
Unit/
Component
Specs
System Test
Integration Test
Module Test
User Acceptance (alpha, beta test)
Review
Analysis /
Review
Analysis /
Review
User review of external behavior as it is
determined or becomes visible
Unit/
Components
Subsystem
Design/Specs
Subsystem
System
Integration
System
Specifications
Delivered
Package
Ch 15, slide 4
(c) 2008 Mauro Pezzè & Michal Young
OO definitions of unit and integration
testing
• Procedural software
– unit = single program, function, or procedure
more often: a unit of work that may correspond to one or more intertwined
functions or programs
• Object oriented software
– unit = class or (small) cluster of strongly related classes
(e.g., sets of Java classes that correspond to exceptions)
– unit testing = intra-class testing
– integration testing = inter-class testing (cluster of classes)
– dealing with single methods separately is usually too expensive (complex
scaffolding), so methods are usually tested in the context of the class they
belong to
Ch 15, slide 5
(c) 2008 Mauro Pezzè & Michal Young
Orthogonal approach: Stages
15.3
Ch 15, slide 6
(c) 2008 Mauro Pezzè & Michal Young
Intraclass State Machine Testing
• Basic idea:
– The state of an object is modified by operations
– Methods can be modeled as state transitions
– Test cases are sequences of method calls that
traverse the state machine model
• State machine model can be derived from
specification (functional testing), code
(structural testing), or both
[ Later: Inheritance and dynamic binding ]
15.4/5
Ch 15, slide 7
(c) 2008 Mauro Pezzè & Michal Young
Informal state-full specifications
Slot: represents a slot of a computer model.
.... slots can be bound or unbound. Bound slots are
assigned a compatible component, unbound slots are
empty. Class slot offers the following services:
• Install: slots can be installed on a model as required or
optional.
...
• Bind: slots can be bound to a compatible component.
...
• Unbind: bound slots can be unbound by removing the
bound component.
• IsBound: returns the current binding, if bound;
otherwise returns the special value empty.
Ch 15, slide 8
(c) 2008 Mauro Pezzè & Michal Young
Identifying states and transitions
• From the informal specification we can identify
three states:
– Not_installed
– Unbound
– Bound
• and four transitions
– install: from Not_installed to Unbound
– bind: from Unbound to Bound
– unbind: ...to Unbound
– isBound: does not change state
Ch 15, slide 9
(c) 2008 Mauro Pezzè & Michal Young
Deriving an FSM and test cases
• TC-1: incorporate, isBound, bind, isBound
• TC-2: incorporate, unBind, bind, unBind, isBound
Ch 15, slide 10
(c) 2008 Mauro Pezzè & Michal Young
Testing with State Diagrams
• A statechart (called a “state diagram” in UML)
may be produced as part of a specification or
design
• May also be implied by a set of message sequence charts
(interaction diagrams), or other modeling formalisms
• Two options:
– Convert (“flatten”) into standard finite-state
machine, then derive test cases
– Use state diagram model directly
Ch 15, slide 11
(c) 2008 Mauro Pezzè & Michal Young
modelSelected
workingConfiguration
noModelSelected
validConfiguration
addComponent(slot, component)
_________________________
send mopdelDB: findComponent()
send slot:bind()
removeComponent(slot)
_________________________
send slot:unbind()
addComponent(slot, component)
_________________________
send Component_DB: get_component()
send slot:bind
deselectModel()
selectModel(model)
_________________
send modelDB: getModel(modelID,this)
removeComponent(slot)
_________________________
send slot:unbind()
isLegalConfiguration()
[legalConfig = true]
Statecharts specification
class model
method of
class Model
called by
class Model
super-state or
“OR-state”
Ch 15, slide 12
(c) 2008 Mauro Pezzè & Michal Young
From Statecharts to FSMs
workingConfiguration
noModelSelected
validConfiguration
addComponent(slot, component)
removeComponent(slot)
addComponent(slot, component)
deselectModel()
selectModel(model)
removeComponent(slot)
isLegalConfiguration()
[legalConfig=true]
deselectModel()
Ch 15, slide 13
(c) 2008 Mauro Pezzè & Michal Young
Statechart based criteria
• In some cases, “flattening” a Statechart to a
finite-state machine may cause “state
explosion”
• Particularly for super-states with “history”
• Alternative: Use the statechart directly
• Simple transition coverage:
execute all transitions of the original Statechart
• incomplete transition coverage of corresponding FSM
• useful for complex statecharts and strong time constraints
(combinatorial number of transitions)
Ch 15, slide 14
Interclass Testing
• The first level of integration testing for object-
oriented software
– Focus on interactions between classes
• Bottom-up integration according to “depends”
relation
– A depends on B: Build and test B, then A
• Start from use/include hierarchy
– Implementation-level parallel to logical “depends” relation
• Class A makes method calls on class B
• Class A objects include references to class B methods
– but only if reference means “is part of”
(c) 2008 Mauro Pezzè & Michal Young
15.6
Ch 15, slide 15
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 16
from a class
diagram...
Order
Customer
1 *
LineItem
1
*
Account
1 0..*
Model Component
Slot
SimpleItem
1 * 1 0..1
USAccount
UKAccount
JPAccount EUAccount
OtherAccount
Package
1 *
ModelDB
CompositeItem
PriceList
*
*
*
*
*
1
CustomerCare
*
*
CSVdb
ComponentDB
SlotDB
*
1
*
1
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 17
....to a hierarchy
Order
Customer
Model
Component
Slot
USAccount
UKAccount
JPAccount EUAccount
OtherAccount
Package
ModelDB
PriceList
CustomerCare
ComponentDB
SlotDB
Note: we may have
to break loops and
generate stubs
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 18
Interactions in Interclass Tests
• Proceed bottom-up
• Consider all combinations of interactions
– example: a test case for class Order includes a call to
a method of class Model, and the called method calls
a method of class Slot, exercise all possible relevant
states of the different classes
– problem: combinatorial explosion of cases
– so select a subset of interactions:
• arbitrary or random selection
• plus all significant interaction scenarios that have been
previously identified in design and analysis: sequence +
collaboration diagrams
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 19
sequence diagram
O:Order C20:Model ChiMod:ModelDB C20Comp:Compoment ChiSlot:SlotDB ChiComp:ComponentDB
selectModel()
getmodel(C20)
extract(C20)
select()
addCompoment(HD60)
contains(HD60)
found
isCompatible(HD60)
C20slot:Slots
incompatible
fail
addCompoment(HD20)
contains(HD20)
found
isCompatible(HD20)
compatible
success
bind
(c) 2008 Mauro Pezzè & Michal Young
Using Structural Information
• Start with functional testing
– As for procedural software, the specification (formal
or informal) is the first source of information for
testing object-oriented software
• “Specification” widely construed: Anything from a
requirements document to a design model or detailed
interface description
• Then add information from the code (structural
testing)
– Design and implementation details not available
from other sources
15.7
Ch 15, slide 20
(c) 2008 Mauro Pezzè & Michal Young
From the implementation ...
public class Model extends Orders.CompositeItem {
....
private boolean legalConfig = false; // memoized
....
public boolean isLegalConfiguration() {
if (! legalConfig) {
checkConfiguration();
}
return legalConfig;
}
.....
private void checkConfiguration() {
legalConfig = true;
for (int i=0; i < slots.length; ++i) {
Slot slot = slots[i];
if (slot.required && ! slot.isBound()) {
legalConfig = false;
} ...} ... }
......
private instance
variable
private method
Ch 15, slide 21
(c) 2008 Mauro Pezzè & Michal Young
Intraclass data flow testing
• Exercise sequences of methods
– From setting or modifying a field value
– To using that field value
• We need a control flow graph that encompasses
more than a single method ...
Ch 15, slide 22
(c) 2008 Mauro Pezzè & Michal Young
The intraclass control flow graph
Control flow for each method
+
node for class
+
edges
from node class to the start
nodes of the methods
from the end nodes of the
methods to node class
=> control flow through sequences
of method calls
Model() 1.1
modelID = NoModel 1.4
exit Model 1.5
boolean legalConfig = false 1.2
ModelDB modelDB = null 1.3
void selectModel(String modelID) 2.1
openDB() 2.2
exit selectModel 2.4
modelDB.getModel(modelID, this) 2.3
void deselectModel() 3.1
modelID = NoModel 3.2
slot = null 3.4
longName = “No ...selected.” 3.3
exit deselectModel 3.5
void removeComponent(int slotIndex) 5.1
slots[slotIndex].unbind() 5.3
if (slots[slotIndex].isBound() 5.2
legalConfig = false 5.4
True
False
exit removeComponent 5.5
void checkConfiguration() 6.1
i < slot.length
if (slot.required && ! slot.isBound()
Slot slot = slots[i]
6.4
legalConfig = false
legalConfig = true
exit checkConfiguration
False
True
++i
int i = 0
True
False
6.3
6.5
6.6
6.7
6.8
6.2
6.9
class
Model
void addComponent(int slotIndex, String sku) 4.1
exit addCompoment 4.10
slot.bind(comp) 4.7
Component comp = new Component(order, sku) 4.3
slot.unbind(); 4.5
legalConfig = false; 4.6
(componentDB.contains(sku)) 4.2
True
(comp.isCompatible(slot.slotID)) 4.4
True
False
False
slot.unbind(); 4.8
legalConfig = false; 4.9
boolean isLegalConfiguration() 7.1
checkCongfiguration()
if (!isLegalConfig)
7.3
True
False
7.2
return legalConfig 7.4
class Model
Method
addComponent
Method
selectModel
Method
checkConfiguration
Ch 15, slide 23
(c) 2008 Mauro Pezzè & Michal Young
Interclass structural testing
• Working “bottom up” in dependence hierarchy
• Dependence is not the same as class hierarchy; not always
the same as call or inclusion relation.
• May match bottom-up build order
– Starting from leaf classes, then classes that use leaf
classes, ...
• Summarize effect of each method: Changing or
using object state, or both
– Treating a whole object as a variable (not just
primitive types)
Ch 15, slide 24
(c) 2008 Mauro Pezzè & Michal Young
Inspectors and modifiers
• Classify methods (execution paths) as
– inspectors: use, but do not modify, instance
variables
– modifiers: modify, but not use instance variables
– inspector/modifiers: use and modify instance
variables
• Example – class slot:
– Slot() modifier
– bind() modifier
– unbind() modifier
– isbound() inspector
Ch 15, slide 25
(c) 2008 Mauro Pezzè & Michal Young
Definition-Use (DU) pairs
instance variable legalConfig
<model (1.2), isLegalConfiguration (7.2)>
<addComponent (4.6), isLegalConfiguration (7.2)>
<removeComponent (5.4), isLegalConfiguration (7.2)>
<checkConfiguration (6.2), isLegalConfiguration (7.2)>
<checkConfiguration (6.3), isLegalConfiguration (7.2)>
<addComponent (4.9), isLegalConfiguration (7.2)>
Each pair corresponds to a test case
note that
some pairs may be infeasible
to cover pairs we may need to find complex sequences
Ch 15, slide 26
(c) 2008 Mauro Pezzè & Michal Young
Definitions from modifiers
Definitions of instance
variable slot in class
model
addComponent (4.5)
addComponent (4.7)
addComponent (4.8)
selectModel (2.3)
removeComponent (5.3)
void addComponent(int slotIndex, String sku) 4.1
exit addCompoment 4.10
slot.bind(comp) 4.7
Component comp = new Component(order, sku) 4.3
slot.unbind(); 4.5
legalConfig = false; 4.6
(componentDB.contains(sku)) 4.2
True
(comp.isCompatible(slot.slotID)) 4.4
True
False
False
slot.unbind(); 4.8
legalConfig = false; 4.9
Slot() modifier
bind() modifier
unbind() modifier
isbound() inspector
Ch 15, slide 27
(c) 2008 Mauro Pezzè & Michal Young
Uses from inspectors
Uses of instance
variables slot in class
model
removeComponent (5.2)
checkConfiguration (6.4)
checkConfiguration (6.5)
checkConfiguration (6.7)
void checkConfiguration() 6.1
i < slot.length
if (slot.required && ! slot.isBound()
Slot slot = slots[i]
6.4
legalConfig = false
legalConfig = true
exit checkConfiguration
False
True
++i
int i = 0
True
False
6.3
6.5
6.6
6.7
6.8
6.2
6.9
Slot() modifier
bind() modifier
unbind() modifier
isbound() inspector
Slot slot =slots[slotIndex];
Ch 15, slide 28
(c) 2008 Mauro Pezzè & Michal Young
Stubs, Drivers, and Oracles for Classes
• Problem: State is encapsulated
– How can we tell whether a method had the correct
effect?
• Problem: Most classes are not complete
programs
– Additional code must be added to execute them
• We typically solve both problems together, with
scaffolding
15.8
Ch 15, slide 29
(c) 2008 Mauro Pezzè & Michal Young
Scaffolding
Driver
Stubs
Classes to
be tested
Tool example:
JUnit
Tool example:
MockMaker
Ch 15, slide 30
(c) 2008 Mauro Pezzè & Michal Young
Approaches
• Requirements on scaffolding approach:
Controllability and Observability
• General/reusable scaffolding
– Across projects; build or buy tools
• Project-specific scaffolding
– Design for test
– Ad hoc, per-class or even per-test-case
• Usually a combination
Ch 15, slide 31
(c) 2008 Mauro Pezzè & Michal Young
Oracles
• Test oracles must be able to check the
correctness of the behavior of the object when
executed with a given input
• Behavior produces outputs and brings an object
into a new state
– We can use traditional approaches to check for the
correctness of the output
– To check the correctness of the final state we need
to access the state
Ch 15, slide 32
(c) 2008 Mauro Pezzè & Michal Young
Accessing the state
• Intrusive approaches
– use language constructs (C++ friend classes)
– add inspector methods
– in both cases we break encapsulation and we may
produce undesired results
• Equivalent scenarios approach:
– generate equivalent and non-equivalent sequences
of method invocations
– compare the final state of the object after
equivalent and non-equivalent sequences
Ch 15, slide 33
(c) 2008 Mauro Pezzè & Michal Young
Equivalent Scenarios Approach
selectModel(M1)
addComponent(S1,C1)
addComponent(S2,C2)
isLegalConfiguration()
deselectModel()
selectModel(M2)
addComponent(S1,C1)
isLegalConfiguration()
EQUIVALENT
selectModel(M2)
addComponent(S1,C1)
isLegalConfiguration()
NON EQUIVALENT
selectModel(M2)
addComponent(S1,C1)
addComponent(S2,C2)
isLegalConfiguration()
Ch 15, slide 34
(c) 2008 Mauro Pezzè & Michal Young
Generating equivalent
sequences
• remove unnecessary (“circular”) methods
selectModel(M1)
addComponent(S1,C1)
addComponent(S2,C2)
isLegalConfiguration()
deselectModel()
selectModel(M2)
addComponent(S1,C1)
isLegalConfiguration()
Ch 15, slide 35
(c) 2008 Mauro Pezzè & Michal Young
Generating non-equivalent scenarios
• Remove and/or
shuffle essential
actions
• Try generating
sequences that
resemble real faults
selectModel(M1)
addComponent(S1,C1)
addComponent(S2,C2)
isLegalConfiguration()
deselectModel()
selectModel(M2)
addComponent(S1,C1)
isLegalConfiguration()
Ch 15, slide 36
(c) 2008 Mauro Pezzè & Michal Young
Verify equivalence
In principle: Two states are equivalent if all possible
sequences of methods starting from those states produce
the same results
Practically:
• add inspectors that disclose hidden state and compare the
results
– break encapsulation
• examine the results obtained by applying a set of methods
– approximate results
• add a method “compare” that specializes the default
equal method
– design for testability
Ch 15, slide 37
Polymorphism and dynamic binding
One variable potentially bound to
methods of different (sub-)classes
15.9
(c) 2008 Mauro Pezzè & Michal Young
“Isolated” calls: the combinatorial
explosion problem
abstract class Credit {
...
abstract boolean validateCredit( Account a, int amt, CreditCard c);
...
}
USAccount
UKAccount
EUAccount
JPAccount
OtherAccount
EduCredit
BizCredit
IndividualCredit
VISACard
AmExpCard
StoreCard
The combinatorial problem: 3 x 5 x 3 = 45 possible combinations
of dynamic bindings (just for this one method!)
Ch 15, slide 39
(c) 2008 Mauro Pezzè & Michal Young
The combinatorial approach
Account Credit creditCard
USAccount EduCredit VISACard
USAccount BizCredit AmExpCard
USAccount individualCredit ChipmunkCard
UKAccount EduCredit AmExpCard
UKAccount BizCredit VISACard
UKAccount individualCredit ChipmunkCard
EUAccount EduCredit ChipmunkCard
EUAccount BizCredit AmExpCard
EUAccount individualCredit VISACard
JPAccount EduCredit VISACard
JPAccount BizCredit ChipmunkCard
JPAccount individualCredit AmExpCard
OtherAccount EduCredit ChipmunkCard
OtherAccount BizCredit VISACard
OtherAccount individualCredit AmExpCard
Identify a set of
combinations that
cover all pairwise
combinations of
dynamic bindings
Same motivation as
pairwise specification-
based testing
Ch 15, slide 40
(c) 2008 Mauro Pezzè & Michal Young
Combined calls: undesired effects
public abstract class Account { ...
public int getYTDPurchased() {
if (ytdPurchasedValid) { return ytdPurchased; }
int totalPurchased = 0;
for (Enumeration e = subsidiaries.elements() ; e.hasMoreElements(); )
{ Account subsidiary = (Account) e.nextElement();
totalPurchased += subsidiary.getYTDPurchased();
}
for (Enumeration e = customers.elements(); e.hasMoreElements(); )
{ Customer aCust = (Customer) e.nextElement();
totalPurchased += aCust.getYearlyPurchase();
}
ytdPurchased = totalPurchased;
ytdPurchasedValid = true;
return totalPurchased;
} … }
Problem:
different implementations of
methods getYDTPurchased
refer to different currencies.
Ch 15, slide 41
(c) 2008 Mauro Pezzè & Michal Young
A data flow approach
public abstract class Account {
...
public int getYTDPurchased() {
if (ytdPurchasedValid) { return ytdPurchased; }
int totalPurchased = 0;
for (Enumeration e = subsidiaries.elements() ; e.hasMoreElements(); )
{
Account subsidiary = (Account) e.nextElement();
totalPurchased += subsidiary.getYTDPurchased();
}
for (Enumeration e = customers.elements(); e.hasMoreElements(); )
{
Customer aCust = (Customer) e.nextElement();
totalPurchased += aCust.getYearlyPurchase();
}
ytdPurchased = totalPurchased;
ytdPurchasedValid = true;
return totalPurchased;
}
…
}
step 1: identify
polymorphic calls, binding
sets, defs and uses
totalPurchased
used and defined
totalPurchased
used and defined
Ch 15, slide 42
(c) 2008 Mauro Pezzè & Michal Young
Def-Use (dataflow) testing of
polymorphic calls
• Derive a test case for each possible
polymorphic <def,use> pair
– Each binding must be considered individually
– Pairwise combinatorial selection may help in
reducing the set of test cases
• Example: Dynamic binding of currency
– We need test cases that bind the different calls to
different methods in the same run
– We can reveal faults due to the use of different
currencies in different methods
Ch 15, slide 43
(c) 2008 Mauro Pezzè & Michal Young
Inheritance
• When testing a subclass ...
– We would like to re-test only what has not been
thoroughly tested in the parent class
• for example, no need to test hashCode and getClass
methods inherited from class Object in Java
– But we should test any method whose behavior may
have changed
• even accidentally!
15.10
Ch 15, slide 44
(c) 2008 Mauro Pezzè & Michal Young
Reusing Tests
with the Testing History Approach
• Track test suites and test executions
– determine which new tests are needed
– determine which old tests must be re-executed
• New and changed behavior ...
– new methods must be tested
– redefined methods must be tested, but we can
partially reuse test suites defined for the ancestor
– other inherited methods do not have to be retested
Ch 15, slide 45
(c) 2008 Mauro Pezzè & Michal Young
Testing history
Ch 15, slide 46
(c) 2008 Mauro Pezzè & Michal Young
Inherited, unchanged
Ch 15, slide 47
(c) 2008 Mauro Pezzè & Michal Young
Newly introduced methods
Ch 15, slide 48
(c) 2008 Mauro Pezzè & Michal Young
Overridden methods
Ch 15, slide 49
(c) 2008 Mauro Pezzè & Michal Young
Testing History – some details
• Abstract methods (and classes)
– Design test cases when abstract method is
introduced (even if it can’t be executed yet)
• Behavior changes
– Should we consider a method “redefined” if another
new or redefined method changes its behavior?
• The standard “testing history” approach does not do this
• It might be reasonable combination of data flow (structural)
OO testing with the (functional) testing history approach
Ch 15, slide 50
(c) 2008 Mauro Pezzè & Michal Young
Testing History - Summary
Ch 15, slide 51
(c) 2008 Mauro Pezzè & Michal Young
Does testing history help?
• Executing test cases should (usually) be cheap
– It may be simpler to re-execute the full test suite of
the parent class
– ... but still add to it for the same reasons
• But sometimes execution is not cheap ...
– Example: Control of physical devices
– Or very large test suites
• Ex: Some Microsoft product test suites require more than
one night (so daily build cannot be fully tested)
– Then some use of testing history is profitable
Ch 15, slide 52
(c) 2008 Mauro Pezzè & Michal Young
Testing generic classes
a generic class
class PriorityQueue<Elem Implements Comparable> {...}
is designed to be instantiated with many different parameter types
PriorityQueue<Customers>
PriorityQueue<Tasks>
A generic class is typically designed to behave consistently
some set of permitted parameter types.
Testing can be broken into two parts
– Showing that some instantiation is correct
– showing that all permitted instantiations behave consistently
15.11
Ch 15, slide 53
Show that some instantiation is correct
• Design tests as if the parameter were copied
textually into the body of the generic class.
– We need source code for both the generic class and
the parameter class
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 54
Identify (possible) interactions
• Identify potential interactions between generic
and its parameters
– Identify potential interactions by inspection or
analysis, not testing
– Look for: method calls on parameter object, access
to parameter fields, possible indirect dependence
– Easy case is no interactions at all (e.g., a simple
container class)
• Where interactions are possible, they will need
to be tested
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 55
Example interaction
class PriorityQueue
<Elem implements Comparable> {...}
• Priority queue uses the “Comparable” interface
of Elem to make method calls on the generic
parameter
• We need to establish that it does so
consistently
– So that if priority queue works for one kind of
Comparable element, we can have some confidence
it does so for others
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 56
Testing variation in instantiation
• We can’t test every possible instantiation
– Just as we can’t test every possible program input
• ... but there is a contract (a specification)
between the generic class and its parameters
– Example: “implements Comparable” is a
specification of possible instantiations
– Other contracts may be written only as comments
• Functional (specification-based) testing
techniques are appropriate
– Identify and then systematically test properties
implied by the specification
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 57
(c) 2008 Mauro Pezzè & Michal Young
Example: Testing instantiation variation
Most but not all classes that implement Comparable also satisfy the
rule
(x.compareTo(y) == 0) == (x.equals(y))
(from java.lang.Comparable)
So test cases for PriorityQueue should include
• instantiations with classes that do obey this rule:
class String
• instantiations that violate the rule:
class BigDecimal with values 4.0 and 4.00
Ch 15, slide 58
(c) 2008 Mauro Pezzè & Michal Young
Exception handling
void addCustomer(Customer theCust) {
customers.add(theCust);
}
public static Account
newAccount(...)
throws InvalidRegionException
{
Account thisAccount = null;
String regionAbbrev = Regions.regionOfCountry(
mailAddress.getCountry());
if (regionAbbrev == Regions.US) {
thisAccount = new USAccount();
} else if (regionAbbrev == Regions.UK) {
....
} else if (regionAbbrev == Regions.Invalid) {
throw new
InvalidRegionException(mailAddress.getCountry());
}
...
}
exceptions
create implicit
control flows
and may be
handled by
different
handlers
15.12
Ch 15, slide 59
Testing exception handling
• Impractical to treat exceptions like normal flow
• too many flows: every array subscript reference, every
memory allocation, every cast, ...
• multiplied by matching them to every handler that could
appear immediately above them on the call stack.
• many actually impossible
• So we separate testing exceptions
• and ignore program error exceptions (test to prevent them,
not to handle them)
• What we do test: Each exception handler, and
each explicit throw or re-throw of an exception
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 60
Testing program exception handlers
• Local exception handlers
– test the exception handler (consider a subset of
points bound to the handler)
• Non-local exception handlers
– Difficult to determine all pairings of <points,
handlers>
– So enforce (and test for) a design rule:
if a method propagates an exception, the method
call should have no other effect
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 61
Summary
• Several features of object-oriented languages
and programs impact testing
– from encapsulation and state-dependent structure
to generics and exceptions
– but only at unit and subsystem levels
– and fundamental principles are still applicable
• Basic approach is orthogonal
– Techniques for each major issue (e.g., exception
handling, generics, inheritance, ...) can be applied
incrementally and independently
(c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 62

More Related Content

Similar to object oriented testing with types of testing

Get the Gist: Universal Modelling Language (UML)
Get the Gist: Universal Modelling Language (UML)Get the Gist: Universal Modelling Language (UML)
Get the Gist: Universal Modelling Language (UML)russellgmorley
 
Hakan Fredriksson - Experiences With MBT and Qtronic
Hakan Fredriksson - Experiences With MBT and Qtronic Hakan Fredriksson - Experiences With MBT and Qtronic
Hakan Fredriksson - Experiences With MBT and Qtronic TEST Huddle
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design PatternGanesh Kolhe
 
unit 3 software requirement and analysis-1.ppt
unit 3 software requirement and analysis-1.pptunit 3 software requirement and analysis-1.ppt
unit 3 software requirement and analysis-1.pptSomnathMule5
 
Software Development Life Cycle Testingtypes
Software Development Life Cycle TestingtypesSoftware Development Life Cycle Testingtypes
Software Development Life Cycle Testingtypesvladimir zaremba
 
FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013Syahriha Ruslan
 
Module 1 Additive Manufacturing
Module 1 Additive ManufacturingModule 1 Additive Manufacturing
Module 1 Additive Manufacturingtaruian
 
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdfsolve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdfarihantcomputersddn
 
Variant configuration-training-document
Variant configuration-training-documentVariant configuration-training-document
Variant configuration-training-documentSantosh Peddi
 
EE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robotEE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robotPraneel Chand
 
10-Testing-system.pdf
10-Testing-system.pdf10-Testing-system.pdf
10-Testing-system.pdfn190212
 
Unit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyUnit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyIRJET Journal
 
Coded ui - lesson 1 - overview
Coded ui - lesson 1 - overviewCoded ui - lesson 1 - overview
Coded ui - lesson 1 - overviewOmer Karpas
 
JMockit Framework Overview
JMockit Framework OverviewJMockit Framework Overview
JMockit Framework OverviewMario Peshev
 
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGFINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGAmira Dolce Farhana
 
Unit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdfUnit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdfKaty Slemon
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and TestingDr Sukhpal Singh Gill
 
From Monolith to Modules - breaking apart a one size fits all product into mo...
From Monolith to Modules - breaking apart a one size fits all product into mo...From Monolith to Modules - breaking apart a one size fits all product into mo...
From Monolith to Modules - breaking apart a one size fits all product into mo...Robert Munteanu
 

Similar to object oriented testing with types of testing (20)

Get the Gist: Universal Modelling Language (UML)
Get the Gist: Universal Modelling Language (UML)Get the Gist: Universal Modelling Language (UML)
Get the Gist: Universal Modelling Language (UML)
 
Hakan Fredriksson - Experiences With MBT and Qtronic
Hakan Fredriksson - Experiences With MBT and Qtronic Hakan Fredriksson - Experiences With MBT and Qtronic
Hakan Fredriksson - Experiences With MBT and Qtronic
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
 
unit 3 software requirement and analysis-1.ppt
unit 3 software requirement and analysis-1.pptunit 3 software requirement and analysis-1.ppt
unit 3 software requirement and analysis-1.ppt
 
Software Development Life Cycle Testingtypes
Software Development Life Cycle TestingtypesSoftware Development Life Cycle Testingtypes
Software Development Life Cycle Testingtypes
 
FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013FP 301 OOP FINAL PAPER JUNE 2013
FP 301 OOP FINAL PAPER JUNE 2013
 
Module 1 Additive Manufacturing
Module 1 Additive ManufacturingModule 1 Additive Manufacturing
Module 1 Additive Manufacturing
 
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdfsolve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
solve 6 , quiz 2link of book httpwww.irccyn.ec-nantes.fr~mart.pdf
 
Variant configuration-training-document
Variant configuration-training-documentVariant configuration-training-document
Variant configuration-training-document
 
EE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robotEE323 Mini-Project - Line tracing robot
EE323 Mini-Project - Line tracing robot
 
Mocking with Mockito
Mocking with MockitoMocking with Mockito
Mocking with Mockito
 
10-Testing-system.pdf
10-Testing-system.pdf10-Testing-system.pdf
10-Testing-system.pdf
 
OODPunit1.pdf
OODPunit1.pdfOODPunit1.pdf
OODPunit1.pdf
 
Unit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyUnit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative study
 
Coded ui - lesson 1 - overview
Coded ui - lesson 1 - overviewCoded ui - lesson 1 - overview
Coded ui - lesson 1 - overview
 
JMockit Framework Overview
JMockit Framework OverviewJMockit Framework Overview
JMockit Framework Overview
 
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMINGFINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
FINAL PAPER FP301 OBJECT ORIENTED PROGRAMMING
 
Unit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdfUnit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdf
 
Software Verification, Validation and Testing
Software Verification, Validation and TestingSoftware Verification, Validation and Testing
Software Verification, Validation and Testing
 
From Monolith to Modules - breaking apart a one size fits all product into mo...
From Monolith to Modules - breaking apart a one size fits all product into mo...From Monolith to Modules - breaking apart a one size fits all product into mo...
From Monolith to Modules - breaking apart a one size fits all product into mo...
 

More from Mani Deepak Choudhry

LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationLM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationMani Deepak Choudhry
 
L13 Plume Rise, types, methods, applications
L13 Plume Rise, types, methods, applicationsL13 Plume Rise, types, methods, applications
L13 Plume Rise, types, methods, applicationsMani Deepak Choudhry
 
L10 Inversions in atmospheric stability, conditions
L10 Inversions in atmospheric stability, conditionsL10 Inversions in atmospheric stability, conditions
L10 Inversions in atmospheric stability, conditionsMani Deepak Choudhry
 
UNIT II - meteorology, occurrence, process
UNIT II - meteorology, occurrence, processUNIT II - meteorology, occurrence, process
UNIT II - meteorology, occurrence, processMani Deepak Choudhry
 
L11 Wind profiles and stack plume patterns.pptx
L11 Wind profiles and stack plume patterns.pptxL11 Wind profiles and stack plume patterns.pptx
L11 Wind profiles and stack plume patterns.pptxMani Deepak Choudhry
 
LM7 - Ambient Air Quality and Emission standards..pptx
LM7 - Ambient Air Quality and Emission standards..pptxLM7 - Ambient Air Quality and Emission standards..pptx
LM7 - Ambient Air Quality and Emission standards..pptxMani Deepak Choudhry
 
LM16 - Gravity Separators, methods, measures
LM16 - Gravity Separators, methods, measuresLM16 - Gravity Separators, methods, measures
LM16 - Gravity Separators, methods, measuresMani Deepak Choudhry
 
LM14,15 - Air Pollution Control, measures
LM14,15 - Air Pollution Control, measuresLM14,15 - Air Pollution Control, measures
LM14,15 - Air Pollution Control, measuresMani Deepak Choudhry
 
LM9 - Fundamentals, Atmospheric stability.pptx
LM9 - Fundamentals, Atmospheric stability.pptxLM9 - Fundamentals, Atmospheric stability.pptx
LM9 - Fundamentals, Atmospheric stability.pptxMani Deepak Choudhry
 
LM8 - Effects of meteorology on Air Pollution.pptx
LM8 - Effects of meteorology on Air Pollution.pptxLM8 - Effects of meteorology on Air Pollution.pptx
LM8 - Effects of meteorology on Air Pollution.pptxMani Deepak Choudhry
 
LM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptx
LM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptxLM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptx
LM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptxMani Deepak Choudhry
 
LM5 - Effect of air Pollutants on Vegetation & animals.pptx
LM5 - Effect of air Pollutants on Vegetation & animals.pptxLM5 - Effect of air Pollutants on Vegetation & animals.pptx
LM5 - Effect of air Pollutants on Vegetation & animals.pptxMani Deepak Choudhry
 
LM4 - Classification of air pollutants and their effect on human health.pptx
LM4 - Classification of air pollutants and their effect on human health.pptxLM4 - Classification of air pollutants and their effect on human health.pptx
LM4 - Classification of air pollutants and their effect on human health.pptxMani Deepak Choudhry
 
LM2 - Definition, Scope & Scales of Air Pollution.pptx
LM2 - Definition, Scope & Scales of Air Pollution.pptxLM2 - Definition, Scope & Scales of Air Pollution.pptx
LM2 - Definition, Scope & Scales of Air Pollution.pptxMani Deepak Choudhry
 
LM1 - Structure & Composition of Atmosphere.pptx
LM1 - Structure & Composition of Atmosphere.pptxLM1 - Structure & Composition of Atmosphere.pptx
LM1 - Structure & Composition of Atmosphere.pptxMani Deepak Choudhry
 
Safety Terminologies, measures, hazards and risks
Safety Terminologies, measures, hazards and risksSafety Terminologies, measures, hazards and risks
Safety Terminologies, measures, hazards and risksMani Deepak Choudhry
 
Software Configuration Management introduction
Software Configuration Management introductionSoftware Configuration Management introduction
Software Configuration Management introductionMani Deepak Choudhry
 
Meta Safety Data Sheets for hazardous materials
Meta Safety Data Sheets for hazardous materialsMeta Safety Data Sheets for hazardous materials
Meta Safety Data Sheets for hazardous materialsMani Deepak Choudhry
 
Personnel Protective Equipment along with measures
Personnel Protective Equipment along with measuresPersonnel Protective Equipment along with measures
Personnel Protective Equipment along with measuresMani Deepak Choudhry
 
types of testing with descriptions and examples
types of testing with descriptions and examplestypes of testing with descriptions and examples
types of testing with descriptions and examplesMani Deepak Choudhry
 

More from Mani Deepak Choudhry (20)

LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationLM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
 
L13 Plume Rise, types, methods, applications
L13 Plume Rise, types, methods, applicationsL13 Plume Rise, types, methods, applications
L13 Plume Rise, types, methods, applications
 
L10 Inversions in atmospheric stability, conditions
L10 Inversions in atmospheric stability, conditionsL10 Inversions in atmospheric stability, conditions
L10 Inversions in atmospheric stability, conditions
 
UNIT II - meteorology, occurrence, process
UNIT II - meteorology, occurrence, processUNIT II - meteorology, occurrence, process
UNIT II - meteorology, occurrence, process
 
L11 Wind profiles and stack plume patterns.pptx
L11 Wind profiles and stack plume patterns.pptxL11 Wind profiles and stack plume patterns.pptx
L11 Wind profiles and stack plume patterns.pptx
 
LM7 - Ambient Air Quality and Emission standards..pptx
LM7 - Ambient Air Quality and Emission standards..pptxLM7 - Ambient Air Quality and Emission standards..pptx
LM7 - Ambient Air Quality and Emission standards..pptx
 
LM16 - Gravity Separators, methods, measures
LM16 - Gravity Separators, methods, measuresLM16 - Gravity Separators, methods, measures
LM16 - Gravity Separators, methods, measures
 
LM14,15 - Air Pollution Control, measures
LM14,15 - Air Pollution Control, measuresLM14,15 - Air Pollution Control, measures
LM14,15 - Air Pollution Control, measures
 
LM9 - Fundamentals, Atmospheric stability.pptx
LM9 - Fundamentals, Atmospheric stability.pptxLM9 - Fundamentals, Atmospheric stability.pptx
LM9 - Fundamentals, Atmospheric stability.pptx
 
LM8 - Effects of meteorology on Air Pollution.pptx
LM8 - Effects of meteorology on Air Pollution.pptxLM8 - Effects of meteorology on Air Pollution.pptx
LM8 - Effects of meteorology on Air Pollution.pptx
 
LM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptx
LM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptxLM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptx
LM6 - Effect of air Pollutants on Property aesthetic value and visibility.pptx
 
LM5 - Effect of air Pollutants on Vegetation & animals.pptx
LM5 - Effect of air Pollutants on Vegetation & animals.pptxLM5 - Effect of air Pollutants on Vegetation & animals.pptx
LM5 - Effect of air Pollutants on Vegetation & animals.pptx
 
LM4 - Classification of air pollutants and their effect on human health.pptx
LM4 - Classification of air pollutants and their effect on human health.pptxLM4 - Classification of air pollutants and their effect on human health.pptx
LM4 - Classification of air pollutants and their effect on human health.pptx
 
LM2 - Definition, Scope & Scales of Air Pollution.pptx
LM2 - Definition, Scope & Scales of Air Pollution.pptxLM2 - Definition, Scope & Scales of Air Pollution.pptx
LM2 - Definition, Scope & Scales of Air Pollution.pptx
 
LM1 - Structure & Composition of Atmosphere.pptx
LM1 - Structure & Composition of Atmosphere.pptxLM1 - Structure & Composition of Atmosphere.pptx
LM1 - Structure & Composition of Atmosphere.pptx
 
Safety Terminologies, measures, hazards and risks
Safety Terminologies, measures, hazards and risksSafety Terminologies, measures, hazards and risks
Safety Terminologies, measures, hazards and risks
 
Software Configuration Management introduction
Software Configuration Management introductionSoftware Configuration Management introduction
Software Configuration Management introduction
 
Meta Safety Data Sheets for hazardous materials
Meta Safety Data Sheets for hazardous materialsMeta Safety Data Sheets for hazardous materials
Meta Safety Data Sheets for hazardous materials
 
Personnel Protective Equipment along with measures
Personnel Protective Equipment along with measuresPersonnel Protective Equipment along with measures
Personnel Protective Equipment along with measures
 
types of testing with descriptions and examples
types of testing with descriptions and examplestypes of testing with descriptions and examples
types of testing with descriptions and examples
 

Recently uploaded

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 

Recently uploaded (20)

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 

object oriented testing with types of testing

  • 1. Testing Object Oriented Software Chapter 15
  • 2. (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 2 Learning objectives • Understand how object orientation impacts software testing – What characteristics matter? Why? – What adaptations are needed? • Understand basic techniques to cope with each key characteristic • Understand staging of unit and integration testing for OO software (intra-class and inter- class testing)
  • 3. (c) 2008 Mauro Pezzè & Michal Young Characteristics of OO Software Typical OO software characteristics that impact testing • State dependent behavior • Encapsulation • Inheritance • Polymorphism and dynamic binding • Abstract and generic classes • Exception handling 15.2 Ch 15, slide 3
  • 4. (c) 2008 Mauro Pezzè & Michal Young Quality activities and OO SW Actual Needs and Constraints Unit/ Component Specs System Test Integration Test Module Test User Acceptance (alpha, beta test) Review Analysis / Review Analysis / Review User review of external behavior as it is determined or becomes visible Unit/ Components Subsystem Design/Specs Subsystem System Integration System Specifications Delivered Package Ch 15, slide 4
  • 5. (c) 2008 Mauro Pezzè & Michal Young OO definitions of unit and integration testing • Procedural software – unit = single program, function, or procedure more often: a unit of work that may correspond to one or more intertwined functions or programs • Object oriented software – unit = class or (small) cluster of strongly related classes (e.g., sets of Java classes that correspond to exceptions) – unit testing = intra-class testing – integration testing = inter-class testing (cluster of classes) – dealing with single methods separately is usually too expensive (complex scaffolding), so methods are usually tested in the context of the class they belong to Ch 15, slide 5
  • 6. (c) 2008 Mauro Pezzè & Michal Young Orthogonal approach: Stages 15.3 Ch 15, slide 6
  • 7. (c) 2008 Mauro Pezzè & Michal Young Intraclass State Machine Testing • Basic idea: – The state of an object is modified by operations – Methods can be modeled as state transitions – Test cases are sequences of method calls that traverse the state machine model • State machine model can be derived from specification (functional testing), code (structural testing), or both [ Later: Inheritance and dynamic binding ] 15.4/5 Ch 15, slide 7
  • 8. (c) 2008 Mauro Pezzè & Michal Young Informal state-full specifications Slot: represents a slot of a computer model. .... slots can be bound or unbound. Bound slots are assigned a compatible component, unbound slots are empty. Class slot offers the following services: • Install: slots can be installed on a model as required or optional. ... • Bind: slots can be bound to a compatible component. ... • Unbind: bound slots can be unbound by removing the bound component. • IsBound: returns the current binding, if bound; otherwise returns the special value empty. Ch 15, slide 8
  • 9. (c) 2008 Mauro Pezzè & Michal Young Identifying states and transitions • From the informal specification we can identify three states: – Not_installed – Unbound – Bound • and four transitions – install: from Not_installed to Unbound – bind: from Unbound to Bound – unbind: ...to Unbound – isBound: does not change state Ch 15, slide 9
  • 10. (c) 2008 Mauro Pezzè & Michal Young Deriving an FSM and test cases • TC-1: incorporate, isBound, bind, isBound • TC-2: incorporate, unBind, bind, unBind, isBound Ch 15, slide 10
  • 11. (c) 2008 Mauro Pezzè & Michal Young Testing with State Diagrams • A statechart (called a “state diagram” in UML) may be produced as part of a specification or design • May also be implied by a set of message sequence charts (interaction diagrams), or other modeling formalisms • Two options: – Convert (“flatten”) into standard finite-state machine, then derive test cases – Use state diagram model directly Ch 15, slide 11
  • 12. (c) 2008 Mauro Pezzè & Michal Young modelSelected workingConfiguration noModelSelected validConfiguration addComponent(slot, component) _________________________ send mopdelDB: findComponent() send slot:bind() removeComponent(slot) _________________________ send slot:unbind() addComponent(slot, component) _________________________ send Component_DB: get_component() send slot:bind deselectModel() selectModel(model) _________________ send modelDB: getModel(modelID,this) removeComponent(slot) _________________________ send slot:unbind() isLegalConfiguration() [legalConfig = true] Statecharts specification class model method of class Model called by class Model super-state or “OR-state” Ch 15, slide 12
  • 13. (c) 2008 Mauro Pezzè & Michal Young From Statecharts to FSMs workingConfiguration noModelSelected validConfiguration addComponent(slot, component) removeComponent(slot) addComponent(slot, component) deselectModel() selectModel(model) removeComponent(slot) isLegalConfiguration() [legalConfig=true] deselectModel() Ch 15, slide 13
  • 14. (c) 2008 Mauro Pezzè & Michal Young Statechart based criteria • In some cases, “flattening” a Statechart to a finite-state machine may cause “state explosion” • Particularly for super-states with “history” • Alternative: Use the statechart directly • Simple transition coverage: execute all transitions of the original Statechart • incomplete transition coverage of corresponding FSM • useful for complex statecharts and strong time constraints (combinatorial number of transitions) Ch 15, slide 14
  • 15. Interclass Testing • The first level of integration testing for object- oriented software – Focus on interactions between classes • Bottom-up integration according to “depends” relation – A depends on B: Build and test B, then A • Start from use/include hierarchy – Implementation-level parallel to logical “depends” relation • Class A makes method calls on class B • Class A objects include references to class B methods – but only if reference means “is part of” (c) 2008 Mauro Pezzè & Michal Young 15.6 Ch 15, slide 15
  • 16. (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 16 from a class diagram... Order Customer 1 * LineItem 1 * Account 1 0..* Model Component Slot SimpleItem 1 * 1 0..1 USAccount UKAccount JPAccount EUAccount OtherAccount Package 1 * ModelDB CompositeItem PriceList * * * * * 1 CustomerCare * * CSVdb ComponentDB SlotDB * 1 * 1
  • 17. (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 17 ....to a hierarchy Order Customer Model Component Slot USAccount UKAccount JPAccount EUAccount OtherAccount Package ModelDB PriceList CustomerCare ComponentDB SlotDB Note: we may have to break loops and generate stubs
  • 18. (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 18 Interactions in Interclass Tests • Proceed bottom-up • Consider all combinations of interactions – example: a test case for class Order includes a call to a method of class Model, and the called method calls a method of class Slot, exercise all possible relevant states of the different classes – problem: combinatorial explosion of cases – so select a subset of interactions: • arbitrary or random selection • plus all significant interaction scenarios that have been previously identified in design and analysis: sequence + collaboration diagrams
  • 19. (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 19 sequence diagram O:Order C20:Model ChiMod:ModelDB C20Comp:Compoment ChiSlot:SlotDB ChiComp:ComponentDB selectModel() getmodel(C20) extract(C20) select() addCompoment(HD60) contains(HD60) found isCompatible(HD60) C20slot:Slots incompatible fail addCompoment(HD20) contains(HD20) found isCompatible(HD20) compatible success bind
  • 20. (c) 2008 Mauro Pezzè & Michal Young Using Structural Information • Start with functional testing – As for procedural software, the specification (formal or informal) is the first source of information for testing object-oriented software • “Specification” widely construed: Anything from a requirements document to a design model or detailed interface description • Then add information from the code (structural testing) – Design and implementation details not available from other sources 15.7 Ch 15, slide 20
  • 21. (c) 2008 Mauro Pezzè & Michal Young From the implementation ... public class Model extends Orders.CompositeItem { .... private boolean legalConfig = false; // memoized .... public boolean isLegalConfiguration() { if (! legalConfig) { checkConfiguration(); } return legalConfig; } ..... private void checkConfiguration() { legalConfig = true; for (int i=0; i < slots.length; ++i) { Slot slot = slots[i]; if (slot.required && ! slot.isBound()) { legalConfig = false; } ...} ... } ...... private instance variable private method Ch 15, slide 21
  • 22. (c) 2008 Mauro Pezzè & Michal Young Intraclass data flow testing • Exercise sequences of methods – From setting or modifying a field value – To using that field value • We need a control flow graph that encompasses more than a single method ... Ch 15, slide 22
  • 23. (c) 2008 Mauro Pezzè & Michal Young The intraclass control flow graph Control flow for each method + node for class + edges from node class to the start nodes of the methods from the end nodes of the methods to node class => control flow through sequences of method calls Model() 1.1 modelID = NoModel 1.4 exit Model 1.5 boolean legalConfig = false 1.2 ModelDB modelDB = null 1.3 void selectModel(String modelID) 2.1 openDB() 2.2 exit selectModel 2.4 modelDB.getModel(modelID, this) 2.3 void deselectModel() 3.1 modelID = NoModel 3.2 slot = null 3.4 longName = “No ...selected.” 3.3 exit deselectModel 3.5 void removeComponent(int slotIndex) 5.1 slots[slotIndex].unbind() 5.3 if (slots[slotIndex].isBound() 5.2 legalConfig = false 5.4 True False exit removeComponent 5.5 void checkConfiguration() 6.1 i < slot.length if (slot.required && ! slot.isBound() Slot slot = slots[i] 6.4 legalConfig = false legalConfig = true exit checkConfiguration False True ++i int i = 0 True False 6.3 6.5 6.6 6.7 6.8 6.2 6.9 class Model void addComponent(int slotIndex, String sku) 4.1 exit addCompoment 4.10 slot.bind(comp) 4.7 Component comp = new Component(order, sku) 4.3 slot.unbind(); 4.5 legalConfig = false; 4.6 (componentDB.contains(sku)) 4.2 True (comp.isCompatible(slot.slotID)) 4.4 True False False slot.unbind(); 4.8 legalConfig = false; 4.9 boolean isLegalConfiguration() 7.1 checkCongfiguration() if (!isLegalConfig) 7.3 True False 7.2 return legalConfig 7.4 class Model Method addComponent Method selectModel Method checkConfiguration Ch 15, slide 23
  • 24. (c) 2008 Mauro Pezzè & Michal Young Interclass structural testing • Working “bottom up” in dependence hierarchy • Dependence is not the same as class hierarchy; not always the same as call or inclusion relation. • May match bottom-up build order – Starting from leaf classes, then classes that use leaf classes, ... • Summarize effect of each method: Changing or using object state, or both – Treating a whole object as a variable (not just primitive types) Ch 15, slide 24
  • 25. (c) 2008 Mauro Pezzè & Michal Young Inspectors and modifiers • Classify methods (execution paths) as – inspectors: use, but do not modify, instance variables – modifiers: modify, but not use instance variables – inspector/modifiers: use and modify instance variables • Example – class slot: – Slot() modifier – bind() modifier – unbind() modifier – isbound() inspector Ch 15, slide 25
  • 26. (c) 2008 Mauro Pezzè & Michal Young Definition-Use (DU) pairs instance variable legalConfig <model (1.2), isLegalConfiguration (7.2)> <addComponent (4.6), isLegalConfiguration (7.2)> <removeComponent (5.4), isLegalConfiguration (7.2)> <checkConfiguration (6.2), isLegalConfiguration (7.2)> <checkConfiguration (6.3), isLegalConfiguration (7.2)> <addComponent (4.9), isLegalConfiguration (7.2)> Each pair corresponds to a test case note that some pairs may be infeasible to cover pairs we may need to find complex sequences Ch 15, slide 26
  • 27. (c) 2008 Mauro Pezzè & Michal Young Definitions from modifiers Definitions of instance variable slot in class model addComponent (4.5) addComponent (4.7) addComponent (4.8) selectModel (2.3) removeComponent (5.3) void addComponent(int slotIndex, String sku) 4.1 exit addCompoment 4.10 slot.bind(comp) 4.7 Component comp = new Component(order, sku) 4.3 slot.unbind(); 4.5 legalConfig = false; 4.6 (componentDB.contains(sku)) 4.2 True (comp.isCompatible(slot.slotID)) 4.4 True False False slot.unbind(); 4.8 legalConfig = false; 4.9 Slot() modifier bind() modifier unbind() modifier isbound() inspector Ch 15, slide 27
  • 28. (c) 2008 Mauro Pezzè & Michal Young Uses from inspectors Uses of instance variables slot in class model removeComponent (5.2) checkConfiguration (6.4) checkConfiguration (6.5) checkConfiguration (6.7) void checkConfiguration() 6.1 i < slot.length if (slot.required && ! slot.isBound() Slot slot = slots[i] 6.4 legalConfig = false legalConfig = true exit checkConfiguration False True ++i int i = 0 True False 6.3 6.5 6.6 6.7 6.8 6.2 6.9 Slot() modifier bind() modifier unbind() modifier isbound() inspector Slot slot =slots[slotIndex]; Ch 15, slide 28
  • 29. (c) 2008 Mauro Pezzè & Michal Young Stubs, Drivers, and Oracles for Classes • Problem: State is encapsulated – How can we tell whether a method had the correct effect? • Problem: Most classes are not complete programs – Additional code must be added to execute them • We typically solve both problems together, with scaffolding 15.8 Ch 15, slide 29
  • 30. (c) 2008 Mauro Pezzè & Michal Young Scaffolding Driver Stubs Classes to be tested Tool example: JUnit Tool example: MockMaker Ch 15, slide 30
  • 31. (c) 2008 Mauro Pezzè & Michal Young Approaches • Requirements on scaffolding approach: Controllability and Observability • General/reusable scaffolding – Across projects; build or buy tools • Project-specific scaffolding – Design for test – Ad hoc, per-class or even per-test-case • Usually a combination Ch 15, slide 31
  • 32. (c) 2008 Mauro Pezzè & Michal Young Oracles • Test oracles must be able to check the correctness of the behavior of the object when executed with a given input • Behavior produces outputs and brings an object into a new state – We can use traditional approaches to check for the correctness of the output – To check the correctness of the final state we need to access the state Ch 15, slide 32
  • 33. (c) 2008 Mauro Pezzè & Michal Young Accessing the state • Intrusive approaches – use language constructs (C++ friend classes) – add inspector methods – in both cases we break encapsulation and we may produce undesired results • Equivalent scenarios approach: – generate equivalent and non-equivalent sequences of method invocations – compare the final state of the object after equivalent and non-equivalent sequences Ch 15, slide 33
  • 34. (c) 2008 Mauro Pezzè & Michal Young Equivalent Scenarios Approach selectModel(M1) addComponent(S1,C1) addComponent(S2,C2) isLegalConfiguration() deselectModel() selectModel(M2) addComponent(S1,C1) isLegalConfiguration() EQUIVALENT selectModel(M2) addComponent(S1,C1) isLegalConfiguration() NON EQUIVALENT selectModel(M2) addComponent(S1,C1) addComponent(S2,C2) isLegalConfiguration() Ch 15, slide 34
  • 35. (c) 2008 Mauro Pezzè & Michal Young Generating equivalent sequences • remove unnecessary (“circular”) methods selectModel(M1) addComponent(S1,C1) addComponent(S2,C2) isLegalConfiguration() deselectModel() selectModel(M2) addComponent(S1,C1) isLegalConfiguration() Ch 15, slide 35
  • 36. (c) 2008 Mauro Pezzè & Michal Young Generating non-equivalent scenarios • Remove and/or shuffle essential actions • Try generating sequences that resemble real faults selectModel(M1) addComponent(S1,C1) addComponent(S2,C2) isLegalConfiguration() deselectModel() selectModel(M2) addComponent(S1,C1) isLegalConfiguration() Ch 15, slide 36
  • 37. (c) 2008 Mauro Pezzè & Michal Young Verify equivalence In principle: Two states are equivalent if all possible sequences of methods starting from those states produce the same results Practically: • add inspectors that disclose hidden state and compare the results – break encapsulation • examine the results obtained by applying a set of methods – approximate results • add a method “compare” that specializes the default equal method – design for testability Ch 15, slide 37
  • 38. Polymorphism and dynamic binding One variable potentially bound to methods of different (sub-)classes 15.9
  • 39. (c) 2008 Mauro Pezzè & Michal Young “Isolated” calls: the combinatorial explosion problem abstract class Credit { ... abstract boolean validateCredit( Account a, int amt, CreditCard c); ... } USAccount UKAccount EUAccount JPAccount OtherAccount EduCredit BizCredit IndividualCredit VISACard AmExpCard StoreCard The combinatorial problem: 3 x 5 x 3 = 45 possible combinations of dynamic bindings (just for this one method!) Ch 15, slide 39
  • 40. (c) 2008 Mauro Pezzè & Michal Young The combinatorial approach Account Credit creditCard USAccount EduCredit VISACard USAccount BizCredit AmExpCard USAccount individualCredit ChipmunkCard UKAccount EduCredit AmExpCard UKAccount BizCredit VISACard UKAccount individualCredit ChipmunkCard EUAccount EduCredit ChipmunkCard EUAccount BizCredit AmExpCard EUAccount individualCredit VISACard JPAccount EduCredit VISACard JPAccount BizCredit ChipmunkCard JPAccount individualCredit AmExpCard OtherAccount EduCredit ChipmunkCard OtherAccount BizCredit VISACard OtherAccount individualCredit AmExpCard Identify a set of combinations that cover all pairwise combinations of dynamic bindings Same motivation as pairwise specification- based testing Ch 15, slide 40
  • 41. (c) 2008 Mauro Pezzè & Michal Young Combined calls: undesired effects public abstract class Account { ... public int getYTDPurchased() { if (ytdPurchasedValid) { return ytdPurchased; } int totalPurchased = 0; for (Enumeration e = subsidiaries.elements() ; e.hasMoreElements(); ) { Account subsidiary = (Account) e.nextElement(); totalPurchased += subsidiary.getYTDPurchased(); } for (Enumeration e = customers.elements(); e.hasMoreElements(); ) { Customer aCust = (Customer) e.nextElement(); totalPurchased += aCust.getYearlyPurchase(); } ytdPurchased = totalPurchased; ytdPurchasedValid = true; return totalPurchased; } … } Problem: different implementations of methods getYDTPurchased refer to different currencies. Ch 15, slide 41
  • 42. (c) 2008 Mauro Pezzè & Michal Young A data flow approach public abstract class Account { ... public int getYTDPurchased() { if (ytdPurchasedValid) { return ytdPurchased; } int totalPurchased = 0; for (Enumeration e = subsidiaries.elements() ; e.hasMoreElements(); ) { Account subsidiary = (Account) e.nextElement(); totalPurchased += subsidiary.getYTDPurchased(); } for (Enumeration e = customers.elements(); e.hasMoreElements(); ) { Customer aCust = (Customer) e.nextElement(); totalPurchased += aCust.getYearlyPurchase(); } ytdPurchased = totalPurchased; ytdPurchasedValid = true; return totalPurchased; } … } step 1: identify polymorphic calls, binding sets, defs and uses totalPurchased used and defined totalPurchased used and defined Ch 15, slide 42
  • 43. (c) 2008 Mauro Pezzè & Michal Young Def-Use (dataflow) testing of polymorphic calls • Derive a test case for each possible polymorphic <def,use> pair – Each binding must be considered individually – Pairwise combinatorial selection may help in reducing the set of test cases • Example: Dynamic binding of currency – We need test cases that bind the different calls to different methods in the same run – We can reveal faults due to the use of different currencies in different methods Ch 15, slide 43
  • 44. (c) 2008 Mauro Pezzè & Michal Young Inheritance • When testing a subclass ... – We would like to re-test only what has not been thoroughly tested in the parent class • for example, no need to test hashCode and getClass methods inherited from class Object in Java – But we should test any method whose behavior may have changed • even accidentally! 15.10 Ch 15, slide 44
  • 45. (c) 2008 Mauro Pezzè & Michal Young Reusing Tests with the Testing History Approach • Track test suites and test executions – determine which new tests are needed – determine which old tests must be re-executed • New and changed behavior ... – new methods must be tested – redefined methods must be tested, but we can partially reuse test suites defined for the ancestor – other inherited methods do not have to be retested Ch 15, slide 45
  • 46. (c) 2008 Mauro Pezzè & Michal Young Testing history Ch 15, slide 46
  • 47. (c) 2008 Mauro Pezzè & Michal Young Inherited, unchanged Ch 15, slide 47
  • 48. (c) 2008 Mauro Pezzè & Michal Young Newly introduced methods Ch 15, slide 48
  • 49. (c) 2008 Mauro Pezzè & Michal Young Overridden methods Ch 15, slide 49
  • 50. (c) 2008 Mauro Pezzè & Michal Young Testing History – some details • Abstract methods (and classes) – Design test cases when abstract method is introduced (even if it can’t be executed yet) • Behavior changes – Should we consider a method “redefined” if another new or redefined method changes its behavior? • The standard “testing history” approach does not do this • It might be reasonable combination of data flow (structural) OO testing with the (functional) testing history approach Ch 15, slide 50
  • 51. (c) 2008 Mauro Pezzè & Michal Young Testing History - Summary Ch 15, slide 51
  • 52. (c) 2008 Mauro Pezzè & Michal Young Does testing history help? • Executing test cases should (usually) be cheap – It may be simpler to re-execute the full test suite of the parent class – ... but still add to it for the same reasons • But sometimes execution is not cheap ... – Example: Control of physical devices – Or very large test suites • Ex: Some Microsoft product test suites require more than one night (so daily build cannot be fully tested) – Then some use of testing history is profitable Ch 15, slide 52
  • 53. (c) 2008 Mauro Pezzè & Michal Young Testing generic classes a generic class class PriorityQueue<Elem Implements Comparable> {...} is designed to be instantiated with many different parameter types PriorityQueue<Customers> PriorityQueue<Tasks> A generic class is typically designed to behave consistently some set of permitted parameter types. Testing can be broken into two parts – Showing that some instantiation is correct – showing that all permitted instantiations behave consistently 15.11 Ch 15, slide 53
  • 54. Show that some instantiation is correct • Design tests as if the parameter were copied textually into the body of the generic class. – We need source code for both the generic class and the parameter class (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 54
  • 55. Identify (possible) interactions • Identify potential interactions between generic and its parameters – Identify potential interactions by inspection or analysis, not testing – Look for: method calls on parameter object, access to parameter fields, possible indirect dependence – Easy case is no interactions at all (e.g., a simple container class) • Where interactions are possible, they will need to be tested (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 55
  • 56. Example interaction class PriorityQueue <Elem implements Comparable> {...} • Priority queue uses the “Comparable” interface of Elem to make method calls on the generic parameter • We need to establish that it does so consistently – So that if priority queue works for one kind of Comparable element, we can have some confidence it does so for others (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 56
  • 57. Testing variation in instantiation • We can’t test every possible instantiation – Just as we can’t test every possible program input • ... but there is a contract (a specification) between the generic class and its parameters – Example: “implements Comparable” is a specification of possible instantiations – Other contracts may be written only as comments • Functional (specification-based) testing techniques are appropriate – Identify and then systematically test properties implied by the specification (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 57
  • 58. (c) 2008 Mauro Pezzè & Michal Young Example: Testing instantiation variation Most but not all classes that implement Comparable also satisfy the rule (x.compareTo(y) == 0) == (x.equals(y)) (from java.lang.Comparable) So test cases for PriorityQueue should include • instantiations with classes that do obey this rule: class String • instantiations that violate the rule: class BigDecimal with values 4.0 and 4.00 Ch 15, slide 58
  • 59. (c) 2008 Mauro Pezzè & Michal Young Exception handling void addCustomer(Customer theCust) { customers.add(theCust); } public static Account newAccount(...) throws InvalidRegionException { Account thisAccount = null; String regionAbbrev = Regions.regionOfCountry( mailAddress.getCountry()); if (regionAbbrev == Regions.US) { thisAccount = new USAccount(); } else if (regionAbbrev == Regions.UK) { .... } else if (regionAbbrev == Regions.Invalid) { throw new InvalidRegionException(mailAddress.getCountry()); } ... } exceptions create implicit control flows and may be handled by different handlers 15.12 Ch 15, slide 59
  • 60. Testing exception handling • Impractical to treat exceptions like normal flow • too many flows: every array subscript reference, every memory allocation, every cast, ... • multiplied by matching them to every handler that could appear immediately above them on the call stack. • many actually impossible • So we separate testing exceptions • and ignore program error exceptions (test to prevent them, not to handle them) • What we do test: Each exception handler, and each explicit throw or re-throw of an exception (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 60
  • 61. Testing program exception handlers • Local exception handlers – test the exception handler (consider a subset of points bound to the handler) • Non-local exception handlers – Difficult to determine all pairings of <points, handlers> – So enforce (and test for) a design rule: if a method propagates an exception, the method call should have no other effect (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 61
  • 62. Summary • Several features of object-oriented languages and programs impact testing – from encapsulation and state-dependent structure to generics and exceptions – but only at unit and subsystem levels – and fundamental principles are still applicable • Basic approach is orthogonal – Techniques for each major issue (e.g., exception handling, generics, inheritance, ...) can be applied incrementally and independently (c) 2008 Mauro Pezzè & Michal Young Ch 15, slide 62