Data wrappers
Data wrappers overview
Within object-oriented programming, a method is a procedure that exists on an object and that can be called by other objects and processes to execute a particular action. In traditional object-oriented programming, a method is not universally aware of all of the application data. It typically has access only to data stored in its object, data that it gets by calling methods on other objects, or data that is passed to it as an input parameter.
This style of strict information exchange is problematic for Behavior Testing Framework scenarios. A scenario can consist of several steps. Each step maps to a step method which, in turn, calls an impl method in one of the context APIs. Steps are intended to be usable in any combination that makes sense from a business perspective, regardless of which classes contain the impl methods that execute the code. Whenever a given method is called, there is no guarantee which methods were executed before it, and which methods will be executed after it. If Behavior Testing Framework followed a strict data exchange paradigm, every method would need to send and received a large number of values to enable all the possible permutations of methods.
To simplify the exchange of information, Behavior Testing Framework uses a set of injected data wrapper objects. A data wrapper is an object that stores information needed by multiple step methods or impl methods. Data wrapper objects are injected into various step classes and impl classes. Whenever a data wrapper is injected into a class, the methods of that class can:
- Retrieve information from the data wrapper object, even though the data wrapper object is not explicitly passed to the method as an input parameter.
- Put information into the data wrapper, even though the data wrapper object is not explicitly returned by the method as a return value.
For example, one of the data wrapper objects is the
_currentUser object. This object is a data wrapper that wraps a String
value. The String value stores the name of the user that will log onto PolicyCenter and
interact with the user interface. When the object is injected into a class, every method in
the class can access the object. The _currentUser object makes it easier to
share the name of the active user across every method in any class that needs this
information.
In the base configuration, the scope of each data wrapper is a single scenario. When the execution of a given scenario is complete, all data wrappers are discarded. The next scenario will use a new set of data wrappers.
Data wrappers are used extensively in Behavior Testing Framework for BillingCenter and ClaimCenter. They are used minimally in Behavior Testing Framework for PolicyCenter and ContactManager.
