Skip to main content

Creating Unit Tests in Pega Robot Studio

4 Tasks

10 mins

Pega Robotic Automation 22.1
Visible to: All users Applies to: Pega Robotic Automation 22.1
Beginner
Robotic Process Automation
English

Scenario

You are a member of the development team responsible for preparing Application Assets for the BankerInsight application. Your current task is to develop Unit Tests for the customerSearch method.  

Complete the following tasks: 

  • Create the 01_CustomerSearch_CustomerNotFound Unit Test using the Convert to unit test option.
  • Create the 02_CustomerSearch_CustomerFound Unit Test using the Unit Test Explorer.
  • Create Setup and cleanup automations for newly created unit tests.
  • Configure Setup and cleanup automations for the test suite. 

You must initiate your own Pega instance to complete this Challenge.

Initialization may take up to 5 minutes so please be patient.

Detailed Tasks

1 Create the customerNotFound unit test using the Convert to unit test option

  1. Download and unpack the folder containing the CreatingUnitTest_Start zip file and move it to C:\Users\<username>\Documents\Pega Robot Studio\
  2. Open CreatingUnitTest_Start.pegaProject in Pega Robot Studio.
  3. In the Project Explorer, click and open the BankerInsight application tab.
  4. Update the Path field of the BankerInsight app to the location of the application on your local computer.
    Note: If you don't have the BankerInsght application installed on your computer, you can download it from the Sample application folder located in your Pega Robot Studio installation path. 
  5. In the Project Explorer, open the BankerInsight folder and then open the Login method.
  6. In the upper-right corner of Pega Robot Studio, click Test to open the Testing automation dialog box.
  7. In the username and password fields enter pega, and then click Test.
  8. In the Test result dialog box click Done to finish the test.
    Verify that the 
    BankerInsight application is running and displays the
    Client Details pane.
  9. In the Project Explorer, open the CustomerSearch method.
  10. In the upper-right corner of Pega Robot Studio, click Test to open the Testing automation dialog box.
  11. In the Testing automation dialog box, in the customerNumber field, enter 111000, and then click Test.
    The testing automation dialog box with the test parameters.
  12. In the Test results dialog box, click Convert to unit test to create a new test using the current test run.
    The Test result dialog box with Convert to unit test button.
  13. In the Add new test case dialog box, in the Test case name, enter 01_CustomerSearch_CustomerNotFound and then click Add. 
    The Add new test case dialog box.
  14. On the Unit tests tab toolbar, click Save all tests.
    The Test Case tab with Save all tests option.

 

2 Create the customerFound unit test using the Unit Test Explorer

  1. In the Test Explorer select CustomerSearch to open the Automation Overview.
    An automation overview tab displaying unit tests status.
  2.  On the Automation Overview, click Add test case.
    The Add test case button on the Automation overview.
  3. In the Add new test case dialog box, in the Test case name field, enter 02_CustomerSearch_CustomerFound, and then click Add.
    The Add new test case dialog box.
  4.  In the Unit Test Explorer, in the Inputs section, enter 40932 in the customerNumber field.
    The Inputs section of the Unit test designer.
  5.  In the Outcome conditions section click Add to create a first condition.
    An empty Outcome conditions section of the Unit test designer, with the Add button used to add the condition.
  6. In the Outcome conditions section, click the + icon to add another condition.
    The Outcome conditions section with the option to add another condition.
  7. In the Field drop-down list select Result, and in the Expected value drop-down list select True.  
    Full set of outcome conditions.
  8. On the toolbar click Save all tests. 

3 Create Setup & cleanup automations

  1. In the Project Explorer, right-click the Unit test folder, and then click Add > Automation.
    The Unit Test forlder i Project Explorer, with option to add a new automation.
  2. In the Add new automation dialog box, in the Automation name field, enter Setup_CustomerSearch, and then click Add. 
  3. On the automation surface, add an Entry and Exit point with no parameters.
  4. On the toolbar, click Include to open the Include in palette dialog box.
  5. In the dialog box, click the Application tab, click the Add button next to the BankerInsight application, and then click Done.
  6. On the palette, expand the Applications section, and then drag the BankerInsight application to the automation surface to open the Select action dialog box.
  7. In the dialog box, click the Method tab, select the StartApp method, and then click Add.
    Adding the application method to the automation using the Select action dialog box.
  8. On the Palette, drag the BankerInsight to the automation surface. 
  9. In the Select action dialog box, select the Login method, and then click Add.
  10. In the Login design block, click the username parameter, and then enter pega.
  11. In the Login design block, click the password parameter, and then enter pega.
  12. On the automation surface, connect the design blocks as shown in the following figure:
    The setup automation for Unit Tests containing StartApp and Login methods.
  13. Repeat steps 1-5 to add a Cleanup_CustomerSearch automation with Entry and Exit points to the Unit Test folder.  
  14. On the Palette, expand the Application section, and then drag the BankerInsight control to the automation surface.
  15. In the Select action dialog box, in the Method tab, select StopApp, and then click Add.
  16. On the automation surface, connect the design blocks as shown in the following figure:
    The cleanup automation containing StopApp method.
  17. On the toolbar, click Save all to save the project.

4 Configure Setup and Cleanup applications for the CustomerSearch test suite

  1. On the Unit tests tab, expand CreatingUnitTests_Start > BankerInsight, and then select the CustomerSearch automation to display the Automation Overview.
    The test explorer with the CustomerSearch test structure.
  2. In the automation pane, click the Setup & cleanup tab. 
  3. In the Configuration for test case section, in The setup automation to run once before execution drop-down list, select Setup_CustomerSearch.
  4. In The cleanup automation to run once after execution drop-down list, select Cleanup_CustomerSearch.
    The Setup & cleanup tab containing confoguration for unit tests.
  5. On the toolbar, click Save all tests.

This Challenge is to practice what you learned in the following Module:


If you are having problems with your training, please review the Pega Academy Support FAQs.

Did you find this content helpful?

Want to help us improve this content?

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