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.

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.

Manage All Tests in Your App UI

When you define multiple tests for each action chain in an App UI, it might be easier to manage tests at the App UI level. You can do this using the Tests tab at the bottom of your browser.



This aggregate view helps you get a quick look at the status of all action chain tests in an App UI. When tests fail, you can use this view to quickly access the editor for each failed test and take action as needed.

While you can also run all tests in your App UI from here, it isn't really required if you've already triggered them. Action chain tests run in the background, even when you're not actively working on your App UI, and the results are saved. So if you are working on an App UI, only tests impacted by your changes (for example, if you added a new variable or updated an existing function) are scheduled to run again. You'll likely see something similar to this image until VB Studio actually runs those tests for you (after 10 seconds of inactivity):
Description of tests-interim-vbs1.png follows
Description of the illustration tests-interim-vbs1.png

This way, your test results are always available and up-to-date, and you can rely on them to identify and fix breaking-code changes.