Create a Test for a Test Case

The first time you access the Tests editor, click the + Test button to create a test for a particular test case. The test name defaults to Test 1; enter a more descriptive name for the test case, if you want.

To create a test for a test case:

  1. In the Context section, provide the initial values for any context variables and constants that are used in the code path that is being tested. For instance, if a variable is used in the code path for a calculation, you'll need to provide a value for the variable that appropriately tests the code path.

    Note:

    If a variable or a constant's value is set by the code being tested and not required to execute the code, you don't provide an initial value for it. The expected value for the variable or constant will be suggested to you as an expectation. For instance, in the example that follows, the value for the variable $page.variables.Answer in set by the Assign Variable action. Since the value is set by code, the expected value for the variable is suggested to you in the Expectations section, as an expectation.
  2. In the Parameters section, provide the values for any input parameters that are used in the code path. In this example, values have been entered for the three input parameters that are used in the addition code path:

  3. In the Mocks section, which shows actions that need their results provided for them, provide the results for any listed actions, and ensure that the values are appropriate for the test case. For instance, if a Call REST action is used, you'll need to provide a response from the Call REST action that properly tests the code for the particular test case.

    These actions always require mocked results:

    • Call Component
    • Call REST
    • Call Variable
    • Get Location
    • Scan Barcode

    To provide a mock for an action, click the action in the Mocks section. In the resulting window, provide a value that is appropriate for the test case.

    If you need to mock a Call REST action, click the Make a REST request to get result data for this mock link to copy a response from a REST request to paste into the Body field:
    Description of jsac-mocks-popup.jpg follows
    Description of the illustration jsac-mocks-popup.jpg

    You will be taken to the Endpoint tab for the Call REST action. Here, you can modify the request to get and copy the response required to mock the action’s result:
    Description of jsac-get-call-rest-return-example.jpg follows
    Description of the illustration jsac-get-call-rest-return-example.jpg

    Shown here are the copied responses from the Call REST action requests, provided as mocks:
    Description of jsac-example-call-rest-results.png follows
    Description of the illustration jsac-example-call-rest-results.png

    To add a mocked result for an action that isn’t shown in the Mocks section, click the Add icon (+) for the Mocks section. Select the action from the Action drop-down list, then provide the value for the test case in the Return field.

  4. Now that you've provided the values for the test case, you can get suggested expectations based on those values by clicking the Get Suggestions button in the Expectations section.

    Shown here are the suggested expectations that are based on the values entered for the Addition Test. In the Expectations section, use the Add All or Add links to add the applicable expectations. To refresh the expectations list, click Refresh:
    Description of jsac-expectations-based-values.jpg follows
    Description of the illustration jsac-expectations-based-values.jpg

    To add your own expectation, click the Add icon (+) for the Expectations section. Select whether you’d like to create an expectation for an action’s parameter, an action’s return value, a context variable, or the action chain’s return value:
    Description of jsac-expectations-box.png follows
    Description of the illustration jsac-expectations-box.png

    Make the appropriate selections for the expectation and provide the expected value, as shown in this example. Click OK:
    Description of jsac-expectations-box-example.png follows
    Description of the illustration jsac-expectations-box-example.png