Chapter 8. Modules

Table of Contents

8.1. Create a Module

To handle the complexity of test cases and to enable reuse of parts of a test case, PETA offers the concept of modules. A module contains a fragment of a test case and can be utilized inside test cases by inserting a reference to it. Thereby, it is a container for PETA events and other modules, enabling hierarchical test case designs.

Test case fragments which are reused in test cases should be implemented as modules to make test case implementation and maintenance easier. But even if the reuse of test case fragments is not feasible, they may be implemented in modules to simplify complex test cases by hiding some details in the modules.

[Note]Further information

Detailed information about PETA modules can be found in the PETA-Core Reference Manual.

8.1. Create a Module

Analyzing the test case requestCourseList , some parts can be identified, which could be useful in other test cases, too. For example, the validation of an incoming request by the server can be reused in other tests. Therefore, this should be implemented in a module.

To create a new PETA module, press the New test module button in the toolbar. Keep the selection on the folder peta/module as the destination folder of the module's file and enter checkRequest as the name of the module.

Figure 8.1. Create a new PETA module

Create a new PETA module


Press the Finish button to create the new module and open it in the editor. As in test case editing, the actors used in the module have to be defined by right clicking in the drawn area and selecting Actor Setup. In the appearing window, select Server only, and press the OK button.

After setting up the module's actor, add an event by dragging and dropping the Add Event symbol from the palette to the actor's lifeline. Name the new event check request and add the same exists assertions like in the test case requestCourseList (see Section 5.8, “Add Assertions” ):

  • an exists assertion on the document path /request (named request received),
  • an exists assertion on the document path /request/type (named request type received , and
  • an exists assertion on the document path /request/timestamp (named request timestamp received).

As this module shall be used in a lot of test cases in which other requests may be sent, it should designed more generic by introducing a context value requestType that is used as an input parameter to assert the expected request type. Drag'n'drop the New Assertion symbol to the event, name it request type as expected, set the operator to == , and set the data type to String . In the left part of the window, press Add document and then press Add Constant to specify the document path /request/type . To compare the document's value with the context value, create a reference by pressing the right Add Reference button and entering requestType as the key (name) of the context value.

Figure 8.2. Assertion using reference to context value

Assertion using reference to context value


Figure 8.3. The complete module

The complete module


The module has been specified now and can be referenced in the test case requestCourseList. In the test case editor, drag'n'drop the Add Module symbol to a place above the server's event. The module will be inserted and the arrow showing the request from the client to the server will be moved to the module's event.

Figure 8.4. Test case after module insertion

Test case after module insertion


As the validation of the request is done in the module's event, the assertions should be removed from the server's event handle request. If necessary, expand this event by double clicking, first. Select an assertion and remove it by right-clicking and selecting Delete from the context menu. Repeat this for all assertions of the event handle request.

Executing the test case now would cause an error, because the context value requestType has not been initialized and is not available. As context values are globally visible and not actor specific, this context value can be initialized in the client's first event. This has the advantage, that it can be used in the template manipulation inside the first event, too.

To create the context value, drag'n'drop the Add Context symbol to the first event, enter requestType as the key, press the Add Constant and enter the constant value getCourseList to which the context value shall be set. To use this context value in the first operation, too, expand the operation part of the first event, select the template and open its wizard by right-clicking and selecting Properties from the context menu.

Figure 8.5. Editing properties of a template

Editing properties of a template


In the wizard, select the substitution and press the Edit button. To replace the constant by a reference to the context value, the constant value first has to be deleted by selecting it and pressing the Remove button. Then, add a reference to the context value by pressing the Add Reference button and entering requestType as the key. Leave the wizard by pressing the OK button.

Figure 8.6. Editing a substitution

Editing a substitution


The test case should now look like this:

Figure 8.7.  Modified test case requestCourseList

Modified test case requestCourseList