You are here: Reference > Rule types > Activities > How to Unit Test an Activity Rule

How to Unit Test an Activity Rule

If your activity requires only a few parameters, you can test it easily using the Run Rule feature. However, if the activity requires extensive setup and is more appropriately tested in context rather than through unit testing, you can trigger the Tracer to start only when the activity is reached.

If you have the AutomatedTesting privilege (through an access role), you can use the features of Automated Unit Testing such as saved test cases and unit test suites for testing your activity. See About Automated Unit Testing and Working with the Test Cases tab for more information.

In-context testing

To test an activity in the context of other activities and rules that produce the needed initial conditions:

  1. Open the activity in the workspace.
  2. Select Actions > Trace . The Tracer tool starts.
  3. Optionally, to avoid using more memory than necessary while tracing, in the Tracer tool window, click Settings to open the Tracer Settings panel, go to the Rulesets To Trace section, and ensure that only the ruleset containing the activity is selected.
  4. Begin the other processing that eventually calls the activity in your own requestor session. Tracer output begins when the activity starts.

Unit testing

For basics of unit testing, see How to unit test a rule with the Run toolbar button.

  1. Optional. Using the Clipboard tool or other means, set up clipboard pages, property values, and other initial conditions for your activity.
  2. Start the Tracer tool if you want to monitor activity execution. Set Tracer options in the Tracer Settings panel.
  3. Click Actions > Run . A pop-up form appears.
  4. If the test requires a test page, select the Create a Test Page radio button. Click Run Rule.
  5. Complete the Test Page area. You can identify an existing clipboard page of an appropriate class as a source of values, or create a new page of that class and initialize values on that page using a data transform.
  6. If the activity uses parameters, the system presents an input form for parameters. Enter constants for input parameters as prompted. (Some input parameters may be optional.)
  7. Click Execute to start the activity in your requestor session.
  8. As the activity runs, it may update your clipboard, open and alter instances, display HTML forms, and so on. It uses your current ruleset list and access roles.
  9. If the execution causes errors, an error form appears.
  10. Use the Clipboard tool and the Tracer tool to uncover errors and view processing details.

Saved test cases and activities

If your operator ID has the AutomatedTesting privilege through an access role, the Run Against a Saved Test Case choice and the Run Test Case button are available if this rule has saved test cases. To run the rule and see how its behavior compares to that in its previously saved test cases, select a choice from the Run Against a Saved Test Case drop-down list. You can choose to unit test against a specific test case or all test cases.

After making your selection, click Run Test Case. If differences are found between results of running the current state of the rule and the saved test case, they are displayed and you have the options of overwriting the saved test case or choosing to ignore differences for future test runs. (See the Playing back saved test cases section in Working with the Test Cases tab.)

Note: If a white list of pages or properties exists for the test case, differences are not reported for pages and properties that are not on the white list. If a white list exists, then only differences for items on the white list are reported. See Test Case form — Understanding the Results tab.

Clipboard contents

Testing with the Run button can create one or more clipboard pages, including copies of named pages you identify on this form. The system retains these pages when you close this form; properties on these pages remain available for later tests of this or another rule tested with the Run button.

If the activity returns results to a parameter marked as Out on the Parameter tab of the activity, you cannot see the results using the Clipboard tool. Out parameters reside on the parameter page of the activity, which you can view only with the Tracer tool. To simplify testing, you can modify the activity temporarily to store an Out parameter value in a property that is visible on a clipboard page. Delete the temporary step when you finish testing.

Notes

You can use this facility if:

About Activities