Docsity

Testing Extensible Design Patterns in Object-Oriented Frameworks through Scenario | CSE 565, Lab Reports of Computer Science

Toggle sidebar
bg1
1
Testing Extensible Design Patterns in Object-Oriented Frameworks through
Scenario Templates
Wei-Tek Tsai
Yongzhong Tu
Weiguang Shao
Ezra Ebner
Software Engineering Laboratory
Department of Computer Science and Engineering
University of Minnesota
Minneapolis, MN
email: {tsai, tu, weiguang, ebner}@cs.umn.edu
Abstract
Design patterns have been used in object-oriented frameworks such as the IBM San
Francisco framework, Apple’s Rhaspody, OpenStep, and WebObjects, and DIWB.
However, few guidelines are available on to effectively test the software developed with
design patterns. This paper first discusses the issues in testing applications developed
with design patterns using an object-oriented framework. Two kinds of design patterns
are available, extensible and static patterns, and this paper focuses on testing
applications using extensible design patterns. Applications developed using extensible
design patterns are difficult to test due to dynamic typing, dynamic binding,
extensibility, and communication complexity. This paper then presents a technique,
Message Framework Sequence Specifications (MfSS), for generating scenario templates
that can be used to generate test cases to test applications developed using extensible
design patterns and an object-oriented framework. Various partition test cases and
random test cases can be generated from a MfSS. Finally, this paper uses the MfSS
technique to test a small bank framework. The test cases generated successfully detected
numerous faults that were seeded in the program.
Keywords : Testing, Testing Object-Oriented Design Patterns, Testing Object-Oriented
Frameworks, Object-Oriented Frameworks, Extensible Design Patterns, Partition
Testing, Random Testing, Scenario Templates.
1. Introduction
Recently, object-oriented design patterns [Gamma 1994, Grand 1998] have been popular.
They provide extensibility in object-oriented frameworks such as the IBM San Francisco
framework [Bohrer 1997, IBMSF 1997], CORBA [Siegel 1996], Apple’s Rhaspody
[Feiler 1997], OpenStep [Gervae 1996] and WebObjects [WebObjects 1997], and the
DIWB [Ebner 1998]. However, few guidelines are available to effectively test
applications developed using design patterns. This paper discusses the issues in testing
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d

Partial preview of the text

Download Testing Extensible Design Patterns in Object-Oriented Frameworks through Scenario | CSE 565 and more Lab Reports Computer Science in PDF only on Docsity!

Testing Extensible Design Patterns in Object-Oriented Frameworks through Scenario Templates

Wei-Tek Tsai Yongzhong Tu Weiguang Shao Ezra Ebner

Software Engineering Laboratory Department of Computer Science and Engineering University of Minnesota Minneapolis, MN email: {tsai, tu, weiguang, ebner}@cs.umn.edu

Abstract

Design patterns have been used in object-oriented frameworks such as the IBM San Francisco framework, Apple’s Rhaspody, OpenStep, and WebObjects, and DIWB. However, few guidelines are available on to effectively test the software developed with design patterns. This paper first discusses the issues in testing applications developed with design patterns using an object-oriented framework. Two kinds of design patterns are available, extensible and static patterns, and this paper focuses on testing applications using extensible design patterns. Applications developed using extensible design patterns are difficult to test due to dynamic typing, dynamic binding, extensibility, and communication complexity. This paper then presents a technique, Message Framework Sequence Specifications (MfSS), for generating scenario templates that can be used to generate test cases to test applications developed using extensible design patterns and an object-oriented framework. Various partition test cases and random test cases can be generated from a MfSS. Finally, this paper uses the MfSS technique to test a small bank framework. The test cases generated successfully detected numerous faults that were seeded in the program.

Keywords : Testing, Testing Object-Oriented Design Patterns, Testing Object-Oriented Frameworks, Object-Oriented Frameworks, Extensible Design Patterns, Partition Testing, Random Testing, Scenario Te mplates.

1. Introduction

Recently, object-oriented design patterns [Gamma 1994, Grand 1998] have been popular. They provide extensibility in object-oriented frameworks such as the IBM San Francisco framework [Bohrer 1997, IBMSF 1997], CORBA [Siegel 1996], Apple’s Rhaspody [Feiler 1997], OpenStep [Gervae 1996] and WebObjects [WebObjects 1997], and the DIWB [Ebner 1998]. However, few guidelines are available to effectively test applications developed using design patterns. This paper discusses the issues in testing

design patterns and presents a technique, Message Framework Sequence Specifications (MfSS), for generating scenario templates that can be used to generate various test cases. Both partition test cases and random test cases can be generated using MfSS. MfSS is an extension of Method Sequence Specifications (MtSS) and Message Seuqnence Specifications (MgSS) [Kirani 1994, Pressman 1997] developed earlier to test object- oriented programs. MfSS was designed to test applications developed using object- oriented frameworks.

Although many quality assurance techniques are available, testing is still the primary method used today in the software industry [Beizer 1995, Tsai 1998]. Many testing techniques have been proposed to test object-oriented programs [Kirani 1994, Pressman 1997]. However, testing design patterns, especially testing design patterns used in object- oriented frameworks, has not been addressed in the literature. Frameworks are partially completed applications when they are released [Taligent 1995]. Frameworks use design patterns to allow the application developer to expand the functionality of the framework [Bohrer 1997, IBMSF 1997, Zhu 1998]. Thus, one of the requirements to test applications developed using frameworks is to test those design patterns that are used in the frameworks.

Patterns can be categorized in to two distinct types, static and extensible. Static patterns are design patterns that do not allow easy extension, while extensible patterns are designed to allow the functionality of the application to change, sometimes even after the compilation of the application that uses the pattern. In other words, it is possible to change the system behavior at runtime by adding objects and/or classes at runtime.

The behavior of static patterns does not change after compilation. Thus, it is easier to test static patterns than to test extensible patterns. An example of a static pattern is a Façade (See Figure 1). A Façade provides an interface to a complex set of subsystems. However, the type and number of subsystems is constant and requires a rebuild for modifications.

Object 2

Object 4

Object 3

Object 1

Object 5

Façade

Figure 1: The Façade Design Pattern

Extensible patterns allow the software to expand by adding new classes to the system. The Factory Method and Visitor patterns (see Figure 2) are two such design pattern that can accepts new classes either at compile time or runtime. Testing extensible patterns is difficult because the tester needs to determine the behavior of the pattern in response to unwritten code, e.g., for those classes that will be loaded at runtime.

2. Issues in Testing Design Patterns

Extensible design patterns are often implemented in object-oriented languages through dynamic binding and dynamic typing. These mechanisms promote reusability but at the same time introduce indirection as many of decisions are postponed until runtime.

2.1. Dynamic Typing

Many object-oriented languages such as objective-C and Java allow dynamic typing where the type of an object is determined at runtime instead of at compile time. For example, an object in Objective-C can be of type “id” and this simply says that the object can be of any type because any other types are subtypes of the type “id”. Thus, any message resolution involving an id object must be done at runtime. This type of dynamic typing is used extensively in WebObjects, OpenStep and Rhapsody. Java also provides similar features by having “Object” as the parent type of all other types. Figure 4 illustrates this issue.

Dynamic typing is a powerful mechanism where the same code can be used to handle all kinds of objects, while the actual methods selected for execution will be determined at runtime. In this way, programs can exhibit dynamic behavior by selecting appropriate objects at runtime. The selection can be done by either the application program or the user without modifying the source code. However, it may also make program understanding and testing difficult.

//The type of “object_parameter” and “screen” are //unknown inside this method. //In addition, the type of “result” will be //determined by the method “performCalculations”. -aMethod :object_parameter display:screen { id result = [object_parameter performCalculations ] [screen show:result]; }

Figure 4: Example WebScript Method with Dynamic Typing

Dynamic typing can be used with extensible design patterns such as Policy, Factory Method, Abstract Method and Visitor. For example, in the Policy (or Strategy) pattern [Gamma 1994], the algorithm selected can be determined at runtime depending on the object that is passed. Thus, extensible design patterns with dynamic typing provide an extremely flexible code that can handle a variety of applications. This is used extensively in WebObjects.

Unfortunately, testing applications using dynamic typing and extensible patterns can be difficult. The tester may not be able to determine the type of an object by looking at the source code alone.

2.2. Dynamic Binding

Object-oriented languages such as Java, C++, Eiffel and Smalltalk often allow dynamic binding where the method to be called is determined at runtime. Dynamic binding poses problems for the tester of the pattern, or an application that uses the patterns. For each test case the tester must determine what method is supposed to be called, since this decision is delayed until runtime, and not necessarily self-evident in the application’s requirements or source code (see Figure 5). //In this example from Microsoft’s MFC, a document may //have multiple views that a user can select to display //the document. The actual method called by the //“pView->UpdateWindow ()” is determined at runtime. //In addition, it is impossible to determine the //actual methods called from this code alone.

void CCustomDocument ::OnRepaintAllViews() { POSITION pos = GetFirstViewPosition(); while (pos != NULL) { CView* pView = GetNextView(pos); pView->UpdateWindow (); } }

Figure 5: Dynamic Linking in MFC’s Document-View Pattern

Extensible design patterns in frameworks contribute additional difficulties because frameworks allow developers to create subclasses of objects given in the framework. These subclasses override existing methods and add new methods to the framework. The framework then uses a callback mechanism to execute the new code.

Recall that many object-oriented languages also allow new classes to be loaded at runtime, and this feature allows the application behavior to change without changing the original source code. This makes testing applications using extensible design patterns even more difficult.

2.3. Extensibility

Extensible design patterns allow application developers to add new classes and methods to frameworks either at compile time or runtime. Considering software testing, one can examine the extensibility from two viewpoints:

  1. Framework developers: The framework developers must provide some level of quality assurance for the users of the framework. Therefore, the framework designers must test the extensible design patterns to verify that they do indeed allow the application developer to expand its functionality. Unfortunately, it is not possible to predict what new classes will be added to the framework by the application developers. The customer code supplied could even be malicious (like a virus).

Figure 6 shows a routine that allows the Policy pattern to link objects into the application at runtime. The only thing that the routine does is get any procedure named "?allocatePolicy@@YAPAVPolicy@@XZ” from the DLL file. This is the factory method for the Policy object. The routine then executes the code at the location in memory returned by the system. The routine assumes that this code is actually a factory method. Anything returned by the code is treated as a Policy object. There is no guarantee that the code will actually return a Policy object. It could return a virus or other malicious code.

2.4. Communications between framework and its application extension part

Frameworks are different from code libraries because framework objects can call custom objects and vice versa. Both directions of calling need to be considered in testing.

Framework Objects Call Custom Objects

Often, custom objects are developed after the framework has been partially completed. This is true even if the developments of the framework and application are concurrent [Suganuma 1998]. In many cases, the framework developer may not know what kinds of custom objects that will be built in the future. In these cases, it is not possible for framework objects to know exactly which custom objects to call. Framework objects may have to use message and event handling mecha nisms such as the Observer pattern or the Strategy pattern [Gamma 1994] to call custom objects at the runtime.

Custom Objects Call Framework Objects

A large framework such as IBM San Francisco framework often chooses to expose certain parts of its software completely with sample code (white box), some other parts as specifications only (gray box), and the rest of parts only as features names (black box). Thus, sometimes a custom object can call a framework object directly (in case of white- box and gray-box exposures), or indirectly via some design patterns (in case of gray-box and black-box exposures).

A framework can be a black box or a white box to the custom objects, depending on the vendor of the framework. So, almost all communication methods are applicable: registration and de-registration (Observer pattern), message return, attempt to change the internal state of the framework (State and Visitor patterns) or direct call.

Frameworks can impose constraints on the way custom objects can interact with framework objects. This is done extensively in the IBM San Francisco framework. Each hook can use a design pattern to help define the interface and behavior between the custom objects and the framework. The framework can define whether the custom object has direct or indirect access to the state of the framework or can define the interface, parameters, and return types for the communication.

Objects communicate through two channels: data structures and messages. Dynamic typing and dynamic binding allow the pattern to abstract the implementation of the

methods used by the custom objects. For example, when using the Factory pattern, the framework defines an interface the custom object must implement. The implementation and data structures used by the factory are hidden from the pattern. If the Visitor pattern is used, the framework defines the interface the Visitor uses to handle the messages, and defines the data structure that the Visitor must use to communicate with the framework. Only the implementation of the methods is hidden from the pattern.

3. Scenario Templates

Multiple custom object types are often associated with one extensible design pattern. For example, in a banking application, withdrawals can be made from a checking account or saving account, and both can be custom objects, but each has its own version of the method withdraw. The checking account’s withdraw may have overdraft protection while the saving account’s may not. Fortunately, the overall sequence of code may be similar in spite of the fact that in different custom objects and different custom methods may be used, and in this way the overall sequence is called a template. Figure 7 illustrates this.

Figure 7: Example message sequence template

This template allows three custom objects are used within the same template. For example, in a banking application all accounts will have the following sequence:

  1. Account creation
  2. Initial deposit
  3. Series of withdrawals and deposits
  4. Final withdrawal from the account
  5. Close the account.

This sequence is independent of the types of accounts in the banking application, i.e., it is valid for savings, checking, and other kinds of accounts. Therefore, a tester can use this sequence to generate scenarios that are valid for multiple custom objects.

3.1. Message Framework Sequence Specifications (MfSS)

Method Sequence Specification (MtSS), and Message Sequence Specification (MgSS) have been used to specify the message interaction between objects in object-oriented applications [Kirani 1994, Kirani 1994-2, Pressman 1997]. Both MtSS and MgSS were

Framework

Object

Custom Object 1

Custom Object 2

Custom Object 3

Message A

Message B

The pattern dynamically binds to one of the custom objects to handle the message

Framework

Object

Securityverifypassword· Helperget-policy · Policyapprove

MfSS is an extension of MtSS and MgSS, and it specifies the sequence constraints on the interaction between frameworks objects and custom objects. In addition, MfSS also specifies dynamic typ ing and dynamic binding. Specifically, symbol { } in a MfSS to indicates dynamic typing. Methods in the { } belong to a custom object and the custom objects are loaded at runtime. Thus, the actual method called is determined at runtime. Similarly, symbol [ ] in a MfSS indicates dynamic binding. Methods in the [ ] are determined at runtime. Since the focus is on the interaction between framework objects and custom objects, {} and [] are used to denote custom objects only. Framework objects may also use dyna mic typing and dynamic binding within their own computation, but they will not highlighted in MfSS.

MtSS is respect to the methods of a single class, MgSS is respect to a method; MfSS is respect to a set of objects. In addition, MfSS also specifies the dynamic behaviors such as dynamic typing and dynamic binding of the objects in the regular expression. See Table

Message Source Message Destination Constrants MtSS Multiple classes Single class Sequence that methods of a class are called MgSS Single class Multiple classes Sequence that a method calls other methods MfSS Multiple classes Multiple classes Sequence that objects should follow Dynamic binding and dynamic typing involved in the sequence are specified. Table 1: Differences of MtSS, MgSS and MfSS

MfSS involves with multiple objects, thus a sequence expression must use object name together with its method name

ObjectName (^) Method • ObjectName (^) Method

In the account example as shown in Figure 8, Account, Security, Helper and Policy objects can be framework objects, but Policy is an extension point where custom objects can be added. Note that a Policy object can be a framework object where a default policy is used or a custom object where a specialized policy is used.

For example, by combining the MtSS and MgSS of the account example above, the following MfSS can be generated for an account object.

MtSS of Account : Create • Open • Deposit • (Checkbalance | Deposit | Withdraw)* • Withdraw

  • Close

MgSS of Withdraw : Securityverifypassword• Helperget-policy • Policyapprove

MgSS of CheckBalance : Security (^) verify-password

MfSS of the Account: Account (^) create • Account (^) open • Account (^) deposit • (Account (^) BalanceCheck • (Security (^) verify-password )| Account (^) deposit | Account (^) widthdraw • (Security (^) verify-password • {Helper (^) getpolicy }•[Policy (^) approve ]))*

  • (Security (^) verify-password • {Helper (^) getpolicy }• [Policy (^) approve ])• Account (^) close

The above MfSS was obtained by inserting the MgSS of Checkbalance and Withdraw into the MtSS of Account.

As shown in the above example, [PolicyApprove] indicates that dynamic binding for the approve method. {Helpergetpolicy} indicates dynamic typing.

In general, an MfSS can be generated by tracing the MtSS of a client object in the framework to the MgSS of custom objects of the framework. Generally, one can start from a client object (using MtSS) in the framework to the hook objects (using MgSS), then from the hook object (using MtSS) to the custom objects of the framework (using MgSS). The sequence is then obtained by tracing the MgSS from one object to another.

3.2. Scenario Templates from the MfSS

Once a MfSS of the application has been determined, then the tester can generate scenario templates that are independent of the different custom object types in the application, by simply selecting one possible sequence of the MfSS. For example, from the MfSS in the previous section, one can generate the following scenario template:

Account (^) create • Account (^) open • Account (^) deposit • Account (^) BalanceCheck • (Security (^) verify-password ) • Account (^) widthdraw • (Security (^) verify-password • {Helper (^) getpolicy }•[Policy (^) approve ]) • Account (^) close

To generate an actual scenario, one needs only plug in concrete objects, such as

SavingAccount (^) create • SavingAccount (^) open • SavingAccount (^) deposit • SavingAccount (^) BalanceCheck • (Security (^) verify-password ) • SavingAccount (^) widthdraw • (Security (^) verify-password • {Helper (^) getpolicy }•[StandardPolicy approve ])^ • SavingAccount (^) close

The above actua l scenario is developed by replacing Account by SavingAccount, and Policy by StandardPolicy. By using different concrete objects, different scenarios can be generated. For example, by replacing the Account by CheckingAccount, and Policy by CustomPolicy, one can obtain the following scenario:

CheckingAccount (^) create • CheckingAccount (^) open • CheckingAccount (^) deposit • CheckingAccount (^) BalanceCheck • (Security (^) verify-password ) •

Account (^) deposit • Check (^) deposit

Conclusion

The conclusion section handles the ending and this section is often custom object dependent. In a banking application, it may be necessary to withdraw all the money in an account before it can be closed. Thus, a reasonable conclusion is:

(Account (^) withdraw • Security (^) verify -password • Helper (^) getPolicy • Policy (^) approve • Check (^) withdraw • (ε | Check delete))^ •^ Account^ close

3.4 Generating Test Cases

The basic sequence for the generation of the test cases from scenario templates is as follows:

  1. Develop the MtSS and MgSS of the framework and its custom objects.
  2. Develop the MfSS of the framework by alternately tracing the MtSS and MgSS from object to object.
  3. Then for each custom object that requires testing in the applications:
  4. Generate the custom object dependant paths and input to provide initialization. For example, in a paint program a circle requires a position and radius for its initialization, while a rectangle requires the coordinates of two opposite corners.
  5. Generate the custom object dependent conclusion for the template. For example, in a bank application, a checking account may need to deduct a fee from the account balance for all overdrafts, while a savings account will simply deny the overdraft.
  6. Generate each custom object’s expected output given the initialization, the template, and the conclusion.

4. Example for Illustration

This section presents a simple banking application to illustrate various testing techniques. The techniques proposed in this paper have been used to test for a variety of applications developed using various frameworks and component models such as CORBA and COM/DCOM. The bank processes checking and saving accounts. It allows a customer to write different types of checks against the balance of a checking account. Before the bank allows withdraws of funds, it must check whether there is sufficient fund in the account as well as the status of the account. A customer cannot withdraw money from a frozen account. The application has been implemented in Java.

4.1. Specifications

The framework implements two types of accounts: checking and saving, and it should allow other types of accounts to be added by application engineers. The bank handles deposits and withdrawals from each account. The bank issues and accepts three kinds of checks:

  1. Personal checks, with values from $0.01 to $10,000;
  2. Cashier’s checks, with values from $0.01 to $1,000,000; and
  3. Money orders, with values from $2 to $300.

The framework uses the Factory Method pattern [Gamma 1994] to create checks, and this allows new kinds of checks to be created by custom objects. The framework also uses the Policy pattern [Gamma 1994] to decide whether a check is honored. The value of each check is deducted from the checking account balance, only if the current Policy object approves the check. Currently the framework has two policies:

  1. Standard. Pay the check as long as the account balance minus the check amount is positive.
  2. Frozen. The account is frozen. Checks are not honored for the account, regardless of the account balance and the amount of the check. New policies can be added by application engineers by using the extensible design pattern Policy.

4.2. Framework and Object Models

Based on these specifications, one possible object model developed for the account application is given in figure 8. In this application, classes Account , Check and Policy are implemented in the framework, they are also the extension points of the framework.

4.3. Scenario Templates

Method Sequence Specifications (MtSS)

Based on the specifications, the MtSS for the various objects are as follows:

  • Account: different MtSSs are available for this object, here is typical one:

Create • Open • (BalanceChecking)* • SetupPolicy • Deposit • (SetupPolicy | Deposit | Withdraw | BalanceChecking | WriteCheck)* • Withdraw • (BalanceChecking)* • Close

The method BalanceChecking can be invoked anytime after the account is opened and before it is closed. An account should not be closed if money is not withdrawn. After an account is opened, its policy may be changed several times from Standard to Frozen or vice versa.

  • Check: a check can be used to withdraw money at first and then used to deposit or vice versa, but cannot be deposited or withdrawn more than once. create • (ε | withdraw • deposit | deposit • withdraw) • delete
  • Policy: create • (approve )* • delete
  • Security: create • (verify-password)* • delete
  • Helper: create • (getPolicy)* • delete

BalanceChecking and close

Table 2: MgSS for Account

There are no messages sent by any of the Policy object’s methods, thus no MgSS. Check object’s methods have no messages sent out either.

Message Framework Sequence Specifications (MfSS)

Start with the MtSS of account objects, one can specify one possible MfSS for the application by tracing MgSS of the methods in the MtSS:

Figure 9: Message framework sequence specification for an account

Account (^) create • Account (^) open • AccountsetupPolicy • (Account (^) deposit • Check (^) deposit • (ε | Check (^) delete )) •

Account (^) Create Account (^) Open Policy^ Policy-Setup

Account (^) Check-Balance

Account (^) Policy-Setup

Account (^) withdraw

Account (^) deposit

Account (^) deposit

Policy (^) approve

Check (^) deposit

Check (^) deposit

Check (^) withdraw

Check (^) delete

Check (^) delete

Security (^) verify-password Check (^) create

Helper (^) getPolicy

Account (^) withdraw

Policy (^) approve

Check (^) withdraw Check (^) delete

Security verify-password

Helper getPolicy

Account (^) close

((Account (^) deposit • Check (^) deposit • (ε | Check (^) delete )) | (Account (^) withdraw • Security (^) verify -password • (ε | Helper (^) getPolicy • Policy (^) approve • (ε | Check (^) withdraw • (ε | Check (^) delete)))) | (Account (^) writeCheck • Check create ) | Account^ checkBalance| AccountsetupPolicy)*^ • (Account (^) withdraw • Security (^) verify -password • Helper (^) getPolicy • Policy (^) approve • Check (^) withdraw • (ε | Check delete))^ •^ Account^ close

In the MfSS, Account (^) create • Account (^) open • AccountsetupPolicy • (Account (^) deposit • Check (^) deposit • (ε | Check delete ))^ is the initialization part,^ (Account^ withdraw •^ Security^ verify -password •^ Helper^ getPolicy •^ Policy^ approve • Check (^) withdraw • (ε | Check (^) delete)) • Account (^) close is the conclusion part, the rest is the template path. This MfSS can be illustrated by Figure 9.

5. Generating Test Cases

Given the scenario templates, testers can focus their testing on different aspects of the application by using common testing techniques such as slicing, partition testing, stress testing, boundary testing, random testing, positive testing and negative testing. Positive testing involved in feeding the system with valid inputs, while negative testing with invalid inputs. One can obtain various types of partition test cases once the scenario templates are available, and some can be involved in boundary testing and stress testing. Random sequences can also be generated giving the scenario templates.

5.1. MfSS Slicing

Program slicing has been a popular technique in software maintenance [Huang 1996]. One can apply the slicing techniques to sequence specifications [Wang 1996] to obtain a subsequence related to certain aspects. This allows testers to focus on a certain aspect of the system. For example, given a MfSS sequence of:

Object1 (^) Message1 • Object2 (^) Message2 • Object1 (^) Message

The sequence can be easily sliced with respect to Object1 and obtain the following subsequence: Object1 (^) Message1 • Object1 (^) Message3.

It is possible to slice a sequence with respect a certain object type, a group of object types, or a collection of methods. By using various criteria, a tester is able to focus on testing certain aspects of the system.

5.2. Partition Testing

Giving a scenario template, various partition testing can be used to generate test cases. This allows for systematic testing of the pattern and the custom objects.

Partitioning According to Object Types

  • No Checking Account + Cashiers Checks

Partitioning According to the Object Input Space

Once the patterns input space has been partitioned according to object or groups of objects, partitioning according to the input space of the individual custom objects can refine the partitions. In the banking example, the checks have different acceptable values that they can be written for, so this can be used to create the following partitions for each check type:

  • Personal Checks
    • Amount < $0.
    • $0.01 <= Amount <= $10,
    • $10,000 < Amount
  • Cashier’s Checks
    • Amount < $0.
    • $0.01 <= Amount <= $1,000,
    • $1,000,000 < Amount
  • Money Orders
    • Amount < $
    • $2 <= Amount <= $
    • $300 < Amount

Once the input space of the pattern is partitioned, the developer has a set of partitions that focus on various aspects of the development. This allows the systematic development of testes by generating the input and expected output for each partition of interest.

Stress Testing

Stress testing runs applications with large number of data. It can be considered as one kind of partition testing where input data are selected from a domain of large values. One can generate the following sample stress test cases for the banking example:

  • Case 1: Open 100M checking accounts.
  • Case 2: Create 100M personal checks.
  • Case 3: Write 100M personal checks with the standard policy.

Boundary Testing

Once an input space has been partitioned, one can generate test cases near the boundaries between domains. For the banking example, the following sample boundary test cases can be generated:

  • Write personal checks for $0.00, $0.01, $9999.99, $10,000.00, and $10,000.

5.3. Negative Testing

Negative testing gives the application invalid input to measure the robustness of the application. Several negative test cases have been discussed in the above subsection. In general, one can generate a variety of invalid objects such as those that are not executable, e.g., wrong binary format and corrupted file.

For the banking application, use the following scenario template

Account (^) withdrawal • Policy (^) approve • Check (^) withdraw

with these invalid objects

  • Account: Checking account that raises an invalid account exception.
  • Checks: Personal Check that raises an invalid check exception.
  • Policy: Policy that raises an invalid policy exception.

In the Factory Method, a method allocates a concrete implementation of an abstract class. To perform negative testing, the Factory Method can return objects with wrong binary format, or not executable code at all, or objects that are not the implementation of the abstract base class.

5.4. Testing Dynamic Typing

Dynamic typing can be tested by running different objects in test cases. For example, the subsequence Account (^) deposit • Check (^) deposit can be run using CheckingAccount objects, SavingingAccount objects, or customAccount (such as an IRASavingAccount ) objects.

This template verifies that the different accounts checks for deposit. It demonstrates that the casts used by the framework and custom objects do not cause failures. When used with the group partitions, it provides an exhaustive test suite for the typing the deposit sequence.

5.5. Testing Dynamic Binding

Dynamic typing implies dynamic binding, but not vice versa. Thus, other than dynamic typing, dynamic binding involved in selecting a method at runtime. In the banking example, approve() is a common method for the StandardPolicy and FrozenPolicy , however, both classes have their individual implementation of the approve().

  • Trying to withdraw money from a frozen account: FrozenPolicyapprove • PersonalCheckwithdraw
  • Trying to withdraw money from a standard account: StandardPolicyapprove • MoneyOrderwithdraw