Professional Documents
Culture Documents
System
Unit Testing Functional Testing Component Testing Testing
Program unit A
Function 1
Program unit B
Component 1
. . Whole
. Function 2 System
. .
. (e.g.
regression
Component 3
testing)
Function 8
Program unit T
Structural (white-box)
Bernd Bruegge & Allen H. Dutoit testing more
Object-Oriented Software functional
Engineering: (Black-box)
Using UML, Patterns, and Java testing
1
Integration Testing
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2
Why Do You Need Integration Testing?
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3 3
Why do we do integration testing?
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4
Stubs and drivers
• Driver:
Driver
• A component, that calls the TestedUnit
• Controls the test cases
Tested
• Stub: Unit
• A component, the TestedUnit
depends on
• Partial implementation
Stub
• Returns fake values.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5
Stubs
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6
Create a stub, step 1
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7
Create a stub, step 2
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8
Create a stub, step 3
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9
"Mock" objects
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 10
Stubs vs. mocks
• A stub gives out data that goes to
the object/class under test.
• The unit test directly asserts against
class under test, to make sure it gives
the right result when fed this data.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11
Example: A 3-Layer-Design (Spreadsheet)
A
Spread
A
SheetView Layer I
B C D
Entity
Data Currency
B Calculator
C D Layer II
Model Converter
E F G
BinaryFile XMLFile Currency Layer III
E F G
Storage Storage DataBase
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12
Big-Bang Approach A
B C D
Test A
Test B
E F G
Test C
Test
Test D A, B, C, D,
E, F, G
Test E
Test F
Test G
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13
Bottom-up Testing Strategy
• The subsystems in the lowest layer of the call
hierarchy are tested individually
• Then the next subsystems are tested that call the
previously tested subsystems
• This is repeated until all subsystems are included
• Drivers are needed.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14
Bottom-up Integration A
B C D
Test E
E F G
Test B, E, F
Test F
Test C Test
A, B, C, D,
E, F, G
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15
Pros and Cons of Bottom-Up Integration Testing
• Con:
• Tests the most important subsystem (user interface)
last
• Drivers needed
• Pro
• No stubs needed
• Useful for integration testing of the following systems
• Object-oriented systems
• Real-time systems
• Systems with strict performance requirements.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16
Top-down Testing Strategy
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17
Top-down Integration A
B C D
E F G
Test
Test A Test A, B, C, D A, B, C, D,
E, F, G
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18
Pros and Cons of Top-down Integration Testing
Pro
• Test cases can be defined in terms of the
functionality of the system (functional
requirements)
• No drivers needed
Cons
• Writing stubs is difficult: Stubs must allow all
possible conditions to be tested.
• Large number of stubs may be required,
especially if the lowest level of the system
contains many methods.
• Some interfaces are not tested separately.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19
Sandwich Testing Strategy
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20
Sandwich Testing Strategy A
B C D
Test A
E F G
Test A,B,C, D
Test E
Test
Test B, E, F A, B, C, D,
Test F E, F, G
Test D,G
Test G
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21
Pros and Cons of Sandwich Testing
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22
Modified Sandwich Testing Strategy
• Test in parallel:
• Middle layer with drivers and stubs
• Top layer with stubs
• Bottom layer with drivers
• Test in parallel:
• Top layer accessing middle layer (top layer
replaces drivers)
• Bottom accessed by middle layer (bottom
layer replaces stubs).
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23
Modified Sandwich Testing A
B C D
Test A
Test A,C
Test C E F G
Test B
Test
Test E Test B, E, F A, B, C, D,
E, F, G
Test F
Test D
Test D,G
Test G
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24
Continuous Testing
• Continuous build:
• Build from day one
• Test from day one
• Integrate from day one
System is always runnable
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25
Continuous Testing Strategy
A
Spread
SheetView Layer I
B C D
Data Currency
Calculator Layer II
Model Converter
E F G
BinaryFile XMLFile Currency Layer III
Storage Storage DataBase
+ Cells
Sheet View + File Storage
+ Addition
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26
Steps in Integration Testing
1.
1. Based
Based onon the
the integration
integration 4.
4. Test
Test subsystem
subsystem
strategy, decomposition:
decomposition: Define
Define test
strategy, select
select aa cases that exercise all
test
component
component to to be
be tested.
tested. cases that exercise all
Unit dependencies
dependencies
Unit test
test all
all the
the classes
classes in
in
. the 5.
5. Test
Test non-functional
the component.
component. non-functional
requirements:
2. requirements: Execute
Execute
2. Put
Put selected
selected component
component performance
performance tests
tests
together;
together; do do anyany 6.
6. Keep
Keep records
records of
of the
the test
test
preliminary
preliminary fix-up
fix-up cases and testing activities.
necessary cases and testing activities.
necessary to make
to make the
the 7.
integration
integration testtest operational
operational 7. Repeat
Repeat steps
steps 11 toto 77 until
until
the full system is tested.
the full system is tested.
(drivers,
(drivers, stubs)
stubs)
3.
3. Test
Test functional
functional
requirements: The
The primary
primary goal goal of
of integration
integration
requirements: Define Define test
test testing
cases testing isis to
to identify
identify failures
failures
cases that
that exercise
exercise allall uses
uses with the (current)
with the (current)
cases
cases with
with the
the selected
selected component
component component configuration.
configuration.
component
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27
Daily builds
• continuous integration:
Adding new units immediately as they are written.
Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28
Some Metrics for Integration Test
based on Structural Decomposition
B C D E
3. C is complete: C is complete:
test with 2 stubs test with driver A
4. D is complete: B is complete:
test with 1 stub test with driver A
5. E is complete: A is complete:
Bernd Bruegge & Allen H. Dutoit test allUsing
Object-Oriented Software Engineering: modules test all modules
UML, Patterns, and Java 30
Slightly Modified Example for the Metrics
A
5. D is complete: B is complete:
test with B test with driver A
6. E is complete: A is complete:
Bernd Bruegge & Allen H. Dutoit
test all modules test all modules
Object-Oriented Software Engineering: Using UML, Patterns, and Java 31