Beruflich Dokumente
Kultur Dokumente
Chapter 15
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
Ch 15, slide 2
15.2
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
Ch 15, slide 3
Review
Delivered
Package
System
Specifications
System Test
Analysis /
Review
Subsystem
Design/Specs
Integration Test
System
Integration
Subsystem
Analysis /
Review
Unit/
Component
Specs
Unit/
Module Test Components
Ch 15, slide 4
Procedural software
Ch 15, slide 5
15.3
Ch 15, slide 6
15.4/5
Ch 15, slide 7
Ch 15, slide 8
Ch 15, slide 9
incorporate
unBind
0
1
Not present
2
Unbound
Bound
isBound
bind
unBind
Ch 15, slide 10
Two options:
Convert (flatten) into standard finite-state
machine, then derive test cases
Use state diagram model directly
Ch 15, slide 11
class model
Statecharts specification
noModelSelected
super-state or selectModel(model)
_________________
OR-state
send modelDB: getModel(modelID,this)
deselectModel()
method of
class Model
modelSelected
addComponent(slot, component)
_________________________
send mopdelDB: findComponent()
send slot:bind()
addComponent(slot, component)
_________________________
send Component_DB: get_component()
send slot:bind
workingConfiguration
isLegalConfiguration()
[legalConfig = true]
validConfiguration
removeComponent(slot)
_________________________
send slot:unbind()
removeComponent(slot)
_________________________
send slot:unbind()
called by
class Model
Ch 15, slide 12
selectModel(model)
addComponent(slot, component)
addComponent(slot, component)
deselectModel()
workingConfiguration
isLegalConfiguration()
[legalConfig=true]
removeComponent(slot)
deselectModel()
removeComponent(slot)
validConfiguration
Ch 15, slide 13
Ch 15, slide 14
15.6
Interclass Testing
The first level of integration testing for objectoriented software
Focus on interactions between classes
Ch 15, slide 15
Customer
Account
0..*
USAccount
Order
OtherAccount
CustomerCare
JPAccount
EUAccount
LineItem
UKAccount
CompositeItem
*
Model
SimpleItem
from a class
diagram...
Package
*
Component
PriceList
0..1
*
Slot
1
ModelDB
*
1
SlotDB
1
ComponentDB
CSVdb
Ch 15, slide 16
....to a hierarchy
USAccount
Customer
Order
CustomerCare
PriceList
Package
OtherAccount
Component
Model
JPAccount
EUAccount
UKAccount
ComponentDB
Slot
ModelDB
SlotDB
Ch 15, slide 17
Ch 15, slide 18
sequence diagram
O:Order
C20:Model
ChiMod:ModelDB
C20Comp:Compoment
C20slot:Slots
ChiSlot:SlotDB
ChiComp:ComponentDB
selectModel()
getmodel(C20)
select()
extract(C20)
addCompoment(HD60)
contains(HD60)
found
isCompatible(HD60)
incompatible
fail
addCompoment(HD20)
contains(HD20)
found
isCompatible(HD20)
compatible
bind
success
Ch 15, slide 19
15.7
Ch 15, slide 20
Ch 15, slide 22
1.1
1.2
openDB()
1.3
modelDB.getModel(modelID, this)
modelID = NoModel
exit Model
1.4
2.1
2.2
void deselectModel()
3.1
modelID = NoModel
3.2
Method
selectModel
exit selectModel
2.3
longName = No ...selected.
slot = null
2.4
1.5
3.3
3.4
exit deselectModel
3.5
class
Model
True
True
slots[slotIndex].unbind()
Component comp = new Component(order, sku)
Method
checkConfiguration
(comp.isCompatible(slot.slotID))
4.5
legalConfig = false;
slot.unbind();
slot.bind(comp)
legalConfig = false
5.4
exit removeComponent
5.5
4.7
4.6
4.8
void checkConfiguration()
legalConfig = false;
legalConfig = true
4.9
exit addCompoment
int i = 0
4.10
True
checkCongfiguration()
if (!isLegalConfig)
7.3
7.1
6.2
6.4
True
7.2
6.5
False
++i
return legalConfig
6.1
6.3
i < slot.length
boolean isLegalConfiguration()
class Model
False
4.4
True
False
slot.unbind();
5.3
4.3
False
5.2
4.2
False
6.6
False
7.4
if (slot.required && ! slot.isBound()
6.7
True
legalConfig = false
6.8
Ch 15, slide 23
Ch 15, slide 24
Slot()
bind()
unbind()
isbound()
modifier
modifier
modifier
inspector
Ch 15, slide 25
Ch 15, slide 26
(componentDB.contains(sku))
True
modifier
modifier
modifier
inspector
(comp.isCompatible(slot.slotID))
slot.unbind();
slot.unbind();
4.4
True
False
4.5
slot.bind(comp)
4.7
4.6
4.8
legalConfig = false;
4.9
exit addCompoment
4.3
False
legalConfig = false;
Slot()
bind()
unbind()
isbound()
4.2
4.10
Ch 15, slide 27
Uses of instance
variables slot in class
model
removeComponent (5.2)
checkConfiguration (6.4)
checkConfiguration (6.5)
checkConfiguration (6.7)
int i = 0
modifier
modifier
modifier
inspector
6.2
6.3
i < slot.length
6.4
True
Slot()
bind()
unbind()
isbound()
6.1
++i
6.5
False
6.6
False
6.7
True
legalConfig = false
6.8
Ch 15, slide 28
15.8
Ch 15, slide 29
Scaffolding
Tool example:
JUnit
Driver
Classes to
be tested
Tool example:
MockMaker
Stubs
Ch 15, slide 30
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
(c) 2008 Mauro Pezz & Michal Young
Ch 15, slide 31
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
Ch 15, slide 33
EQUIVALENT
selectModel(M2)
addComponent(S1,C1)
isLegalConfiguration()
NON EQUIVALENT
selectModel(M2)
addComponent(S1,C1)
addComponent(S2,C2)
isLegalConfiguration()
Ch 15, slide 34
Generating equivalent
sequences
remove unnecessary (circular) methods
selectModel(M1)
addComponent(S1,C1)
addComponent(S2,C2)
isLegalConfiguration()
deselectModel()
selectModel(M2)
addComponent(S1,C1)
isLegalConfiguration()
(c) 2008 Mauro Pezz & Michal Young
Ch 15, slide 35
selectModel(M1)
addComponent(S1,C1)
addComponent(S2,C2)
isLegalConfiguration()
deselectModel()
selectModel(M2)
addComponent(S1,C1)
isLegalConfiguration()
Ch 15, slide 36
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
Ch 15, slide 37
15.9
EduCredit
BizCredit
IndividualCredit
USAccount
UKAccount
EUAccount
JPAccount
OtherAccount
VISACard
AmExpCard
StoreCard
Ch 15, slide 39
Same motivation as
pairwise specificationbased testing
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
Ch 15, slide 40
methods getYDTPurchased
refer to different currencies.
Ch 15, slide 41
totalPurchased
used and defined
totalPurchased
used and defined
Ch 15, slide 42
Ch 15, slide 43
15.10
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
Ch 15, slide 44
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
Ch 15, slide 45
Testing history
Ch 15, slide 46
Inherited, unchanged
Ch 15, slide 47
Ch 15, slide 48
Overridden methods
Ch 15, slide 49
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
Ch 15, slide 51
Ch 15, slide 52
15.11
Ch 15, slide 53
Ch 15, slide 54
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
Ch 15, slide 57
Ch 15, slide 58
15.12
Exception handling
void addCustomer(Customer theCust) {
exceptions
customers.add(theCust);
create implicit
}
control flows
public static Account
and may be
newAccount(...)
handled by
throws InvalidRegionException
different
{
handlers
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());
}
...
} (c) 2008 Mauro Pezz & Michal Young
Ch 15, slide 59
Ch 15, slide 60
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
Ch 15, slide 62