Skip to main content

Unit testing rules

Archived

3 Tasks

15 mins

Visible to: All users
Beginner Pega Platform 8.6 DevOps English
This content is now archived and is no longer updated. Progress is not calculated. Pega Cloud instances are disabled, and badges are no longer awarded.

Scenario

For an Assistance Request case, when users enter the vehicle make, one or more associated models display in the Model drop-down. Intermittently, users report that during the Submit request process, when entering the vehicle information, some car makes do not have an associated model name in the drop-down. Stakeholders need to easily identify the vehicle makes without at least one associated model.

In addition, stakeholders are concerned about application performance. To ensure customers can complete assistance request cases efficiently, stakeholders require that the vehicle model list is generated within 200 milliseconds.

The following table provides the credentials you need to complete the challenge.

Role User name Password
Application Developer tester@gogoroad pega123!
Note: Your practice environment may support the completion of multiple challenges. As a result, the configuration shown in the challenge walkthrough may not match your environment exactly.

Challenge Walkthrough

Detailed Tasks

1 Run the List Vehicle models data page and test different Make values

  1. In the navigation pane of Dev Studio, click Data types to open the Data types explorer.
  2. Expand Vehicle models, and then click List Vehicle models to edit the D_VehiclemodelsList data page.
    The Data types explorer, with the Vehicle models data type expanded and the List Vehicle models data page selected.
    Note: If the List Vehicle models data page does not display in the Data Explorer, click Options > Refresh to refresh the explorer.
  3. In the upper right, click Actions > Run. The Run Data Page window is displayed.
  4. For the make parameter, in the Value field, enter Tesla as the test value.
  5. For the modelyear parameter, in the Value field, enter 2017 as the test value.
  6. In the upper right, click Run to test the data page.
  7. Expand the pxResults property and confirm that the property includes three results pages.
    A successful unit test of the List Vehicle models data page, with three results returned.
  8. For the make parameter, in the Value field, enter Saturn, and then click Run. The pxResults property is no longer displayed, which confirms that not all vehicle makes have at least one associated model.

    A completed unit test of the List Vehicle models data page, with no results returned.

 

2 Create a unit test

  1. In the Run Data Page window, for the make parameter, in the Value field enter Tesla.
  2. In the upper right, click Run. The Convert to test button is displayed.
  3. Click Convert to test to close the Run Data Page window and create a test case record for the data page that uses the results of your test.
    The Convert to test button, which creates a test case from a successful unit test result.
    Note: The parameter values entered in the Run Data Page window are automatically populated in the Test Case form.
    A unit test record, with the parameters to the tested rule highlighted.
  4. On the Test Case form, in the Expected results section, verify that the Assertion type drop-down value is Expected run time.
  5. In the Value field, enter 0.2 to set the passing threshold for the unit test to 0.2 seconds.
    Unit test expected run time 0.2 seconds
  6. In the second Assertion type list, select Result count
  7. In the of object field, enter or select .pxResults.
  8. In the Comparator list, select is greater than.
  9. In the Value field, enter 0. The unit test validates that at least 1 record is returned from the data page when the Make parameter value is Tesla.
    Assertion type
  10. Click Save.
  11. In the Label field, enter VehicleModelsList_Tesla to name the test case record.
  12. In the Add to ruleset and version lists, verify that the highest ruleset version is selected.
    The Test Case Record configuration form, filled out to create a test case.
  13. Click Submit.

3 Create unit tests for different vehicle makes

  1. In the VehicleModelsList_Tesla test case, to the right of Save, click the down arrow
    Save down arrow
  2. Click Save as.
  3. In the Label field, enter VehicleModelsList_Ford.
  4. Click Create and open to save a copy of the test case.
  5. To the right of Class, click the Gear icon to open the Edit details window and update the rule parameters.
    A unit test case record with the gear icon highlighted, indicating where to click to change the test parameters.
  6. In the Parameter(s) sent section, in the make field, enter Ford.
    Changing the value of the make parameter from Tesla to Ford.
  7. Click Submit to close the Edit details window.
  8. In the Description section, click the Pencil icon to edit the vehicle make.
  9. Following the text parameters, <make:, update Tesla with Ford.
    unit-testing-vehicle-model-ford
  10. Click Save to complete the configuration of the unit test. 
  11. Repeat steps 1-10, using VehicleModelsList_Saturn as the test case label and Saturn as the make parameter.
    unit-testing-vehicle-model-saturn

Confirm your work

  1. From the Configure menu, click Application > Quality > Automated testing > Unit testing > Test cases to display all the unit tests that you created for the GoGoRoad application.
  2. To the left of the Test case name column, select the check box to select all the test cases.
  3. Click Run selected to execute the unit tests.
    unit-testing-run-selected-test-cases
  4. In the Result column verify that the Tesla and Ford unit test cases passed and the Saturn unit test case failed.
    unit-testing-test-run-results
  5. To the right of Failed, click View to see additional information and investigate why the Saturn test case failed. The Test Runs Log dialog box is displayed.
  6. Click the test result. The test results for VehicleModelsList_Saturn are displayed.
    unit-testing-saturn-test-case-result


Available in the following mission:

We'd prefer it if you saw us at our best.

Pega Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice