Module 5-Implementation and Testing
Module 5-Implementation and Testing
TESTING
MODULE 5
OBJECTIVES
Upon the completion of this module, the students are
expected to:
• Name
• Observer.
• Description
• Separates the display of object state from the object itself.
• Problem description
• Used when multiple displays of state are needed.
• Solution description
• See slide with UML description.
• Consequences
• Optimisations to enhance display performance are impractical.
The Observer pattern (1)
Pattern Observer
name
Description Separates the display of the state of an object from the object itself and
allows alternative displays to be provided. When the object state
changes, all displays are automatically notified and updated to reflect the
change.
Problem In many situations, you have to provide multiple displays of state
description information, such as a graphical display and a tabular display. Not all of
these may be known when the information is specified. All alternative
presentations should support interaction and, when the state is changed,
all displays must be updated.
This pattern may be used in all situations where more than one
display format for state information is required and where it is not
necessary for the object that maintains the state information to know
about the specific display formats used.
The Observer pattern (2)
Pattern name Observer
Solution This involves two abstract objects, Subject and Observer, and two concrete
description objects, ConcreteSubject and ConcreteObject, which inherit the attributes of the
related abstract objects. The abstract objects include general operations that are
applicable in all situations. The state to be displayed is maintained in
ConcreteSubject, which inherits operations from Subject allowing it to add and
remove Observers (each observer corresponds to a display) and to issue a
notification when the state has changed.
Consequences The subject only knows the abstract Observer and does not know details of the
concrete class. Therefore there is minimal coupling between these objects.
Because of this lack of knowledge, optimizations that enhance display
performance are impractical. Changes to the subject may cause a set of linked
updates to observers to be generated, some of which may not be necessary.
Multiple displays using the Observer
pattern
A UML model of the Observer pattern
Design problems
• To use patterns in your design, you need to recognize that any
design problem you are facing may have an associated pattern
that can be applied.
• Tell several objects that the state of some other object has changed
(Observer pattern).
• Tidy up the interfaces to a number of related objects that have often been
developed incrementally (Façade pattern).
• Provide a standard way of accessing the elements in a collection,
irrespective of how that collection is implemented (Iterator pattern).
• Allow for the possibility of extending the functionality of an existing class
at run-time (Decorator pattern).
Implementation issues
• Focus here is not on programming, although this is obviously
important, but on other implementation issues that are often not
covered in programming texts:
• Reuse Most modern software is constructed by reusing existing
components or systems. When you are developing software, you should
make as much use as possible of existing code.
• Configuration management During the development process, you have to
keep track of the many different versions of each software component in
a configuration management system.
• Host-target development Production software does not usually execute
on the same computer as the software development environment. Rather,
you develop it on one computer (the host system) and execute it on a
separate computer (the target system).
Reuse
• From the 1960s to the 1990s, most new software was developed
from scratch, by writing all code in a high-level programming
language.
• The only significant reuse or software was the reuse of functions and
objects in programming language libraries.
• Costs and schedule pressure mean that this approach became
increasingly unviable, especially for commercial and Internet-
based systems.
• An approach to development based around the reuse of existing
software emerged and is now generally used for business and
scientific software.
Reuse levels
• The abstraction level
• At this level, you don’t reuse software directly but use knowledge of
successful abstractions in the design of your software.
• The object level
• At this level, you directly reuse objects from a library rather than writing
the code yourself.
• The component level
• Components are collections of objects and object classes that you reuse in
application systems.
• The system level
• At this level, you reuse entire application systems.
Reuse costs
• The costs of the time spent in looking for software to reuse and
assessing whether or not it meets your needs.
• Where applicable, the costs of buying the reusable software. For
large off-the-shelf systems, these costs can be very high.
• The costs of adapting and configuring the reusable software
components or systems to reflect the requirements of the system
that you are developing.
• The costs of integrating reusable software elements with each
other (if you are using software from different sources) and with
the new code that you have developed.
Configuration management
• Verification:
"Are we building the product right”.
• The software should conform to its specification.
• Validation:
"Are we building the right product”.
• The software should do what the user really requires.
V & V confidence
• Aim of V & V is to establish confidence that the system is ‘fit for
purpose’.
• Depends on system’s purpose, user expectations and marketing
environment
• Software purpose
• The level of confidence depends on how critical the software is to an organisation.
• User expectations
• Users may have low expectations of certain kinds of software.
• Marketing environment
• Getting a product to market early may be more important than finding defects in the
program.
Inspections and testing
• Software inspections Concerned with analysis of
the static system representation to discover
problems (static verification)
• May be supplement by tool-based document and code analysis.
• Discussed in Chapter 15.
• Software testing Concerned with exercising and
observing product behaviour (dynamic verification)
• The system is executed with test data and its operational
behaviour is observed.
Inspections and testing
Software inspections
• These involve people examining the source representation with the aim of
discovering anomalies and defects.
• Inspections not require execution of a system so may be used before
implementation.
• They may be applied to any representation of the system (requirements,
design, configuration data, test data, etc.).
• They have been shown to be an effective technique for discovering program
errors.
Advantages of inspections
• During testing, errors can mask (hide) other errors. Because
inspection is a static process, you don’t have to be concerned with
interactions between errors.
• Incomplete versions of a system can be inspected without
additional costs. If a program is incomplete, then you need to
develop specialized test harnesses to test the parts that are
available.
• As well as searching for program defects, an inspection can also
consider broader quality attributes of a program, such as
compliance with standards, portability and maintainability.
Inspections and testing
• Inspections and testing are complementary and not opposing verification
techniques.
• Both should be used during the V & V process.
• Inspections can check conformance with a specification but not conformance
with the customer’s real requirements.
• Inspections cannot check non-functional characteristics such as performance,
usability, etc.
A model of the software testing
process
Stages of testing
• Choose inputs that force the system to generate all error messages
• Design inputs that cause input buffers to overflow
• Repeat the same input or series of inputs numerous times
• Force invalid outputs to be generated
• Force computation results to be too large or too small.
Component testing
• Software components are often composite components that are
made up of several interacting objects.
• For example, in the weather station system, the reconfiguration
component includes objects that deal with each aspect of the
reconfiguration.
• You access the functionality of these objects through the defined
component interface.
• Testing composite components should therefore focus on showing
that the component interface behaves according to its
specification.
• You can assume that unit tests on the individual objects within the
component have been completed.
Interface testing
Interface testing
• Objectives are to detect faults due to interface errors or invalid
assumptions about interfaces.
• Interface types
• Parameter interfaces Data passed from one method or procedure to
another.
• Shared memory interfaces Block of memory is shared between
procedures or functions.
• Procedural interfaces Sub-system encapsulates a set of procedures to be
called by other sub-systems.
• Message passing interfaces Sub-systems request services from other sub-
systems
Interface errors
• Interface misuse
• A calling component calls another component and makes an error in its use of its
interface e.g. parameters in the wrong order.
• Interface misunderstanding
• A calling component embeds assumptions about the behaviour of the called component
which are incorrect.
• Timing errors
• The called and the calling component operate at different speeds and out-of-date
information is accessed.
88
Interface testing guidelines
• Design tests so that parameters to a called procedure are at the extreme ends
of their ranges.
• Always test pointer parameters with null pointers.
• Design tests which cause the component to fail.
• Use stress testing in message passing systems.
• In shared memory systems, vary the order in which components are
activated.
System testing