Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ObjectOrientedSoftwareEngineering
Chapter 11,
Testing
Third Lecture:
Model-based Testing
U2TP Testing Profile
Testing strategy
Design patterns &
testing
System testing
Function testing
Acceptance testing.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava2
Famous Problems
F-16 : crossing equator using autopilot
Result: plane flipped over
Reason?
Reuse of autopilot
software
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava3
Terminology
Failure: Any deviation of the observed behavior
from the specified behavior
Erroneous state (error): The system is in a state
such that further processing by the system can
lead to a failure
Fault: The mechanical or algorithmic cause of an
error (bug)
Validation: Activity of checking for deviations
between the observed behavior of a system and
its specification.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava4
What is this?
A failure?
An error?
A fault?
We need to describe specified
and desired behavior first!
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava5
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava6
Algorithmic Fault
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava7
Mechanical Fault
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava8
F-16 Bug
Rocket
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava9
Algorithmic
Algorithmic Faults
Faults
Operating
Operating temperature
temperature
outside
of
equipment
outside of equipment
specification
specification
Errors
Errors
Null
Null reference
reference errors
errors
Concurrency
Concurrency errors
errors
Exceptions.
Exceptions.
Missing
Missing initialization
initialization
Incorrect
Incorrect branching
branching
condition
condition
Missing
Missing test
test for
for null
null
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava10
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava11
Modular Redundancy
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava12
Declaring the
Bug
as a Feature
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava13
Patching
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava14
Testing
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava15
Fault detection
Testing: Activity to provoke failures in a planned way
Debugging: Find and remove the cause (Faults) of an
observed failure
Monitoring: Deliver information about state => Used
during debugging
Fault tolerance
Exception handling
Modular redundancy.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava16
Fault
Avoidance
Methodoloy
Fault
Detection
Configuration
Management
Fault
Tolerance
Atomic
Transactions
Modular
Redundancy
Verification
Testing
Unit
Testing
Integration
Testing
BerndBruegge&AllenH.Dutoit
Debugging
System
Testing
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava17
Observations
It is impossible to completely test any nontrivial
module or system
Practical limitations: Complete testing is prohibitive in
time and cost
Theoretical limitations: e.g. Halting problem
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava18
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava19
Unit
Testing
Testing Activities
Integration
Testing
System
Testing
Object
Design
Document
System
Design
Document
Requirements
Analysis
Document
Client
Expectation
Unit
Testing
Integration
Testing
System
Testing
Acceptance
Testing
Developer
BerndBruegge&AllenH.Dutoit
Acceptance
Testing
Client
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava20
Types of Testing
Unit
Testing
Integration
Testing
System
Testing
Acceptance
Testing
Unit Testing
Individual component (class or subsystem)
Carried out by developers
Goal: Confirm that the component or subsystem is
correctly coded and carries out the intended
functionality
Integration Testing
Groups of subsystems (collection of subsystems) and
eventually the entire system
Carried out by developers
Goal: Test the interfaces among the subsystems.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava21
Unit
Testing
Integration
Testing
System
Testing
Acceptance
Testing
System Testing
The entire system
Carried out by developers
Goal: Determine if the system meets the requirements
(functional and nonfunctional)
Acceptance Testing
Evaluates the system delivered by developers
Carried out by the client. May involve executing typical
transactions on site on a trial basis
Goal: Demonstrate that the system meets the
requirements and is ready to use.
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava22
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava23
Unit
Testing
Unit Testing
Integration
Testing
System
Testing
Acceptance
Testing
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava24
Unit
Testing
Integration
Testing
System
Testing
Acceptance
Testing
Checkstyle
Check for code guideline violations
http://checkstyle.sourceforge.net
FindBugs
Check for code anomalies
http://findbugs.sourceforge.net
Metrics
Check for structural anomalies
http://metrics.sourceforge.net
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava25
Black-box testing
Unit
Testing
Integration
Testing
System
Testing
Acceptance
Testing
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava26
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava27
Representationformonth:
1:January,2:February,.,12:December
Representationforyear:
1904,1999,2000,,2006,
Howmanytestcasesdoweneedfortheblackboxtestingof
getNumDaysInMonth()?
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava28
Unit
Testing
Integration
Testing
System
Testing
Acceptance
Testing
Code coverage
Branch coverage
Condition coverage
Path coverage
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava29
BerndBruegge&AllenH.Dutoit
4.
4. Desk
Desk check
check your
your source
source code
code
Sometimes
Sometimes reduces
reduces testing
testing
time
time
5.
5. Create
Create aa test
test harness
harness
Test
Test drivers
drivers and
and test
test stubs
stubs
are
needed
for
integration
are needed for integration
testing
testing
6.
6. Describe
Describe the
the test
test oracle
oracle
Often
Often the
the result
result of
of the
the first
first
successfully
successfully executed
executed test
test
7.
7. Execute
Execute the
the test
test cases
cases
Re-execute
Re-execute test
test whenever
whenever aa
change
change isis made
made
(regression
(regression testing)
testing)
8.
8. Compare
Compare the
the results
results of
of the
the
test
test with
with the
the test
test oracle
oracle
Automate
Automate this
this ifif possible.
possible.
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava30
JUnit: Overview
Unit
Testing
Integration
Testing
System
Testing
Acceptance
Testing
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava31
JUnit Classes
*
Test
TestResult
run(TestResult)
TestCase
testName:String
run(TestResult)
setUp()
tearDown()
runTest()
ConcreteTestCase
setUp()
tearDown()
runTest()
BerndBruegge&AllenH.Dutoit
TestSuite
run(TestResult)
addTest()
UnitToBeTested
MethodsunderTest
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava32
add()
remove()
contains()
size()
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava33
*
Test
TestResult
run(TestResult)
TestCase
testName:String
run(TestResult)
setUp()
tearDown()
runTest()
MyListTestCase
setUp()
tearDown()
runTest()
testAdd()
testRemove()
TestSuite
run(TestResult)
addTest()
MyList
add()
remove()
contains()
size()
*
Test
TestResult
run(TestResult)
TestCase
testName:String
BerndBruegge&AllenH.Dutoit
run(TestResult)
setUp()
tearDown()
runTest()
MyListTestCase
setUp()
tearDown()
runTest()
testAdd()
testRemove()
TestSuite
run(TestResult)
addTest()
MyList
add()
remove()
contains()
size()
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava35
BerndBruegge&AllenH.Dutoit
Test Fixture
Test Case
Test Case
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava36
Test
Composite Pattern!
run(TestResult)
TestCase
testName:String
run(TestResult)
setUp()
tearDown()
runTest()
BerndBruegge&AllenH.Dutoit
TestSuite
run(TestResult)
addTest()
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava37
TestResult
Command Pattern
run(TestResult)
Composite
Pattern
Template Method
Pattern
Adapter
Pattern
TestCase
testName:String
run(TestResult)
setUp()
tearDown()
runTest()
ConcreteTestCase
TestSuite
run(TestResult)
addTest()
TestedUnit
setUp()
tearDown()
runTest()
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava38
TestResult
Command Pattern
run(TestResult)
Composite
Pattern
Template Method
Pattern
Adapter
Pattern
TestCase
testName:String
run(TestResult)
setUp()
tearDown()
runTest()
ConcreteTestCase
TestSuite
run(TestResult)
addTest()
TestedUnit
setUp()
tearDown()
runTest()
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava39
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava40
Additional Readings
JUnit Website www.junit.org/index.htm
BerndBruegge&AllenH.Dutoit
ObjectOrientedSoftwareEngineering:UsingUML,Patterns,andJava41