To keep the quality high a lot of tests are needed to check the existing code. The Test Model Framework supports the developer to create preconditions for tests.
A test model is a simple helper class, which can be used to create an instance of a special type like business object or a persistent object.
The main concept of the framework is to fasten up the setup of a test environment where the tests are executed. Each test model should 'know' by itself what it needs and automatically creates the missing test model.
To instantiate a new model only the
get() method on a static member of the test model is needed. All depending stuff, which is needed for the model is created automatically.
For example there is a test model
ProductLineItemTM. This test model creates a
ProductLineItem instance. It automatically creates the corresponding objects (basket, user, product, price, address, warranty, etc.) that are needed. The developer does not need to know all the necessary objects, which are required for that test model.
The different occurrences of the test models are just static members in that test model class.
When a test model is created the first time it uses an internal
create() method. The test model stores the created model internally and later calls will just return this model.
Take care, that these static members are not changed during a test.
After the test, a simple call of
TestModel.clearAll() removes all created test models. Please use it in combination with
setAutoCleanup(true). The method
clearAll() only removes the internal references, but will not remove the models from the data base.
If you want a different instance of a test model, which is not defined as a static member of that class, add another static member. All the information for this test model should be defined via the constructor. When changing the logic it is recommended to extend the test model and create an inner class. Thus, you can collect all different test models (static members) of that type in one class.
You can also create new test model for a new model. For that purpose, extend the class
AbstractTestModel<T>. It is abstract and you must implement the abstract method
T create(). The generic T is the type of the model you want to create with that test model.
Define one or more constructor to set the attributes of the test model. In the
create() method you can create the model with the help of the attributes, given by the constructor.
Every test needs exactly one test model of
OrganizationStructureTM. It can also indirectly be created by other test models like the
There is only one step needed for each test class to set up the needed cartridges at the organization structure. Call the method (e.g.
, OrganizationStructureTM.organizationStructure1.setTestCartridges(yourTestCartridgeList). This method expects a array of strings representing the cartridges.
The class diagram is very simple. Every test model inherits from
AbstractTestModel handles the creation of the model. Therefore, it calls the
create() method, which must be implemented by the test model. It also caches the created model internally.
TestModel is implemented by the
get() is called, then the internal
create() method is called, which creates the model. Every other method call of
get() delivers the cached model. The method
clear() removes the cached model. So the next call of
get() creates a new model.
The static method
clearAll() removes all cached Models for every test model instance. This method should be called at the end of a test.
At the moment all existing test models belong to the catridge sld_ch_b2c_base_test. Basically, it is intended to move a test model to the corresponding cartridge. As an example,
BasketTM will be moved to b c_basket_test.
TestModel and the class
AbstractTestModel are located in the cartridge etest.
The information provided in the Knowledge Base may not be applicable to all systems and situations. Intershop Communications will not be liable to any party for any direct or indirect damages resulting from the use of the Customer Support section of the Intershop Corporate Web site, including, without limitation, any lost profits, business interruption, loss of programs or other data on your information handling system.