Test case creation
Unit testing provides a means for you to quickly check and verify that the logic of an automation functions as expected. A test case runs the automation with the given input values and compares the output to the output condition in the case. The test passes if the actual output is the same as the expected output.
There are two ways to create a test case for unit testing:
- Create a test case in the Test results dialog box after running an automation in Test mode.
- Create a test case manually by accessing the Unit Test feature in the Tools menu.
The quickest and simplest way to create a test case is to create one in the Test results dialog box. When you create a test case from the Test results dialog box, the system automatically transfers any input values and the output condition to a test case. Conversely, when you manually enter a test case, you must enter the input values and output conditions yourself.
When unit testing an automation , a developer should account for each possible exit. In the following figure of an automation that searches for a specific customer number, the Automation fails if it cannot find the customer number or if either the last name or the personal ID does not match the input values:
In the previous automation example, four specific exit labels can account for four test cases: three Failed points and one Success point. Creating a test case to account for each of these verifies that any change to the automation must still follow the logical paths in the automation. If the test cases fail, you can locate and resolve any issue in a short time.
New test case
As a best practice, create unit test cases in the Test results dialog box. Clicking Convert to unit test displays the Add new test case window, as shown in the following figure. By using this process, you can create a test case that automatically captures the input values and test results.
You can also create test cases in the Unit Tests Explorer, and manually define inputs and outcomes. For more information, see Adding test cases.
Test Case window
After creating a test case, you configure the test case in the Test Case window. The Test Case window provides basic information about the test case, including inputs, outcomes, and recent activities. You can also set batch run options.
In the following image, click the + icons to learn more about each area of the Test Case window:
The Inputs and Outcome conditions are the key parts of a test case. The input values are the automation's input parameters. The Outcome conditions are a Boolean comparison to some expected value.
For example, in the Customer Search example above, you would set input values for custNumber, lastName, and persID. To test the first failure condition, you enter a custNumber value that you know is not in your system, such as 8675309. Then, you set your outcome conditions to expect your msgDetails output parameter to equal BI004 and the Result output parameter to be False.
When you create test cases in the Test results dialog box, the test case inputs and outcome conditions are set automatically from the inputs and outputs of the Test scenario that you ran manually. As a result, you can quickly create test cases from a known effective automation by running it multiple times with different input values.
Outcome conditions
Outcome conditions define the behavior you expect the automation to exhibit given the input values for the test case, and you can define outcome conditions manually on the Test Case window, as shown in the following figure:
The Relationship list provides you with a list of options depending on the type of parameter that you selected in the Field list. The Expected value also depends on the Field type and Relationship defined. Depending on these factors, you might have the option to either enter a value, such as in the case of a String output parameter or select from a list of predefined options.
You can use the Conditional expression field to customize the Boolean expression being tested. By default, all conditions must pass for the test case to pass. For example, if you have three conditions in your test case, the default Conditional expression would be 1 AND 2 AND 3. However, you can set your own custom Boolean expression by selecting the Advanced checkbox under the field.
Boolean expressions can use various operators such as AND, OR, and NOT as well as parentheses for grouping conditions. The expression must contain all the conditions in the test case. The system considers a test case as passsing when the Conditional expression evaluates to True.
Check your knowledge with the following interaction:
This Topic is available in the following Module:
Want to help us improve this content?