Test Action Chains

VB Studio can help you test the flow of your action chains by generating suggestions of outcomes to validate in a Tests editor. You can use this editor to apply a test-driven approach to developing action chains.

The Tests editor detects what information needs to be provided at runtime to perform actions in an action chain. This information includes values for variables and constants used by the action chain, and actions like Call REST endpoint, the results of which need to be mocked when running a test. Once the necessary context is provided, the editor generates suggestions for expected outcomes (expectations) that you can add to the test. You can also add your own expectations.

Access this editor from the Tests tab in the Actions editor of an individual action chain. The first time you access the Tests editor, click the + Test button to create a test. The test name defaults to Test 1; specify an alternative name, if you want.

Once in the editor, you can create one or more tests for the associated action chain. For each test, you define context, mock actions, and expectations.
  • A context refers to a variable that the action chain uses. If, for example, you have an action chain that uses a Call Function that takes a subtotal variable as input and returns the total after tax, you add a context entry that includes the subtotal variable and a sample value for the variable. To add a context, click Add Context icon in the Properties pane next to Context.
  • Mock actions are needed for Call REST endpoint actions and other actions in the action chain. For each mock action, you specify a possible outcome for the action and a result. If, for example, your action chain includes a Call REST endpoint action that fetches product information, you need to specify a mock action that has a success outcome and includes a sample result of product information. To add a mock action, click Add Mock icon in the Properties pane next to Mock. Or, right-click the action for which you need to define a mock action and select Mock Action from the context menu.
  • Finally, you specify expectations for the test. VB Studio generates a set of suggested expectations that you can add to the test. You can add one or more of these to the test and edit the expected outcome. To add an expectation, click Add Expectation icon in the Properties pane next to Expectations, or click Get Suggestions. You can also right-click the action for which you need to define an expectation and select Add Expectation from the context menu.

Once you've defined the tests, you can run them individually or all at once using the Run or Run All button. You can also run these tests using the vb-test Grunt task (see Test Action Chains Using the vb-test Grunt Task).

The following image shows three tests defined for an action chain that fetches product information: Description of test-overview-threetests.png follows
Description of the illustration test-overview-threetests.png

Two of these tests have run (Failure Path and Success Path), one has not (Test Three). The red icon beside the Failure Path test indicates that it failed; the reason for the failure is also marked red in the expectation for the fireNotification message, where the test author set the expected outcome to Action Failed but the actual outcome was undefined. The green icon beside the Success Path test indicates that the test succeeded. No visual indicator appears beside Test Three because it has not yet been executed.

The percent value for Coverage indicates the level of test coverage for the actions in the action chain. If you create tests that include all actions in the action chain and all expected outcomes for the actions, the percent value for Coverage will be 100%. In the preceding image, the test author has removed some entries from the Expectations list for the Failure Path test, thereby reducing the action chain's Coverage value. You can increase the Coverage value by adding entries that appear under the Suggestions list to the Expectations list.

The source code for your tests is stored in a separate JSON file for easier maintenance, one actionchainname-tests.json file for all the tests in an action chain. To view this file's contents, click JSON in the left pane. You can also find this file under the artifact's chains folder in the Navigator's Source View tab.