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.
New Feature: Submodels are available in Eggplant AI 2.2 and later.
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.
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.)
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:
- Select an action in the center pane to which you want to connect a submodel.
- 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.
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.
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.
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:
- Select an action in the workspace where you have an attached submodel.
- 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.
- 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.