Using Submodels in Eggplant AI

When you are modeling large or complex applications and systems, it might be useful to take a modular approach to creating your models. To facilitate modularization, Eggplant AI lets you use submodels. A submodel is a model that you connect to an action of another model in the same way you connect code snippets. In this way, you can build large models out of smaller, modularized pieces.

Working with Submodels

As you build your models, you might focus on individual sections or subsystems of your applications in order to slowly build up the total picture of what you need to test. If you take this approach from the start, it should be easy to see how you might employ submodels in Eggplant AI to bring together all the pieces of your application.

With this approach, you can test sections of your application independently, and also bring the independent models together into a top-level model for comprehensive testing by linking the section models as submodels. Linking submodels within actions allow you to define a hierarchy of different levels of model to describe your application. When selecting actions to execute, Eggplant AI’s path selection algorithm considers paths in the submodel that haven’t been traversed yet.

Using the Models Tab

Any model can be used as a submodel. To see your available models, select the Models tab in the left pane of Eggplant AI. The Models tab lists any model you have created as well as any model saved within your group. (For information about groups in Eggplant AI, see Eggplant AI Administration.)

Use the Models tab in the left pane to link other models as submodels in Eggplant AI

You can use the filter field to narrow the number of models that display. The filter is applied as you type.

With the Models tab selected, follow these steps to add a model as a submodel:

  1. Select an action in the center pane to which you want to connect a submodel.
  2. On the Models tab, right-click the model you want to attach, then select Add to selected as submodel. Alternatively, click the arrow next to the model name to add the submodel.

Each action has two dots in the upper-left corner. The right dot turns green when a submodel is attached. The left dot indicates if a snippet is attached. If you hover your cursor over a green dot, a tooltip shows what snippet or submodel is attached.

An Eggplant AI action with an attached submodel shows a green dot on the right

You can connect both snippets and submodels to the same action. When both snippets and submodels are attached to an action, snippets run first, followed by submodels.

Running Tests with Submodels

The process of running a test with a submodel is no different from any other test execution in Eggplant AI. When you click Play on the toolbar, the model begins with the initial state and chooses a path through the model. When it selects an action that has a submodel attached, the execution switches to that secondary model.

In the Eggplant AI console, you can see that the model has called the submodel, and what steps are performed there. The model view in the workspace, however, doesn't change—it still shows the single highlighted action that called the submodel.

Eggplant AI console text describes actions in the submodel while the model in the workspace shows the highlighted action that called the submodel

After the submodel completes successfully, execution of the parent model resumes from that point, just as it would for an attached snippet.

If you want to exclude the submodel from test execution, select Disabled in the Action Properties tab.

Select this checkbox to disable submodels

You also can include submodels in directed test cases.

Using Variables with Submodels

You can pass variable values between submodels and the parent model. You might use this capability to set a specific path within the submodel, for example. Or you could use a returned value to check whether a certain state or action in the submodel was hit during execution.

You need to define the variable as a global variable in both the parent model and the submodel. That is, the variable name and definition must match in both models. Such variables can be created just like any other global variable. With no state or action selected, choose one of these options:

  • Right-click in the model workspace, then select New Variable.
  • On the Global Properties tab in the right sidebar, click New in the Global Variables section.

The new variable appears as a line in the Global Variables section with a default name. You can click in the fields to customize the Name, Type, Generation method, and Initial Value, as necessary.

Remember that you need to create the variable in both the parent model and the submodel.

After you create your variables, in the parent model, you need to associate them with the submodel:

  1. Select an action in the workspace where you have an attached submodel.
  2. In the Submodels Called by Action section of the Action Properties tab in the right pane, right-click the attached submodel and select Edit Passthrough Variables.
    Right-click a submodel in the Submodels Called by Action section to associate the variables you want to pass to an Eggplant AI submodel
  3. In the Submodel I/O Editor dialog box, select the checkbox in the selected column for any variable you want to pass between the submodel and the parent model. Click OK to close the dialog box and save your selections.

Note: If the variable you pass into a submodel has a value, that value overwrites any initial value that might be set for the variable in the submodel.

If a variable value is updated during the submodel run and passed back to the parent model, the new value overwrites the variable in the parent model when the submodel exits.

 

This topic was last updated on August 19, 2021, at 03:30:47 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant