Skip to main content

Unit testing using Pega software

Automated unit testing is a key aspect in the Continuous Development and Continuous Integration (CI/CD) model of application development.

Create tests

Pega Platform™ offers the PegaUnit framework to support unit testing of Pega Platform applications. This framework is available out-of-the-box at no additional licensing cost. Each rule in the application is considered as a “unit,” and automated unit tests can be created for the application rules using this framework. The PegaUnit framework provides native support to thirteen key rule types across various rule categories, as shown in the following image:

Rule type supported by PegaUnit

 Check your knowledge with the following interaction:

The PegaUnit framework includes the following important features:

  • Create tests intuitively
  • Configure multiple validations with flexibility
  • Set up and clean up test data
  • Create test suites 
  • Manage tests
  • View key metrics
  • Integrate with CI/CD

Intuitive tests

Apart from having the knowledge of working with Pega rules and applications, users and clients need no additional technical knowledge to work with this framework. Users first need to run a supported rule manually. Upon satisfactory results, users can convert the same run into an automated unit test by creating necessary validations. You can run the unit tests that you create manually or in an automated fashion by using a test suite or a continuous integration (CI) pipeline.

Multiple validations with flexibility

PegaUnit offers validations to meet different output verification needs, while unit testing application rules.

The following image shows the validations that are supported by the PegaUnit framework: 

Validations supported by PegaUnit framework

Setup and Cleanup

An important aspect of any test framework is the ability to set up and clean the test data; this enables users to create tests that are independent of the environment. It is recommended that users create tests that are independent for execution, thereby avoiding any error that might arise due to dependencies.

The Setup section of the PegaUnit test case enables users to set prerequisite data needed for the rule being tested to run independently. The Setup section consists of three parts:

  • Before rule execution: This section enables users to copy clipboard pages and configure manual steps to create the required test data on the clipboard.
  • Simulation: This section enables users to simulate rules and supply custom data as the output from the simulated rules,  such that the rule under test can proceed with the supplied data instead of making calls to the rules. 
Note: Currently, simulation support is available for only data page and connect rules.
  • After rule execution: This section enables users to perform some operations after the rule runs, but before validations happen. 

For example:

  • Reload any page that the rule under test removes
  • Order the resultant data in a particular order before validations occur

The Cleanup section of the PegaUnit test case enables users to choose whether they need to perform an automatic test data cleanup at the end of the test. Additionally, this section also provides options to create steps that are necessary to clean the test data manually. 

Check your knowledge with the following interactions:

Creation of test suites

PegaUnit framework enables users to create test suites to logically group test cases for various testing needs. This feature helps do focused testing. The following list shows some ways that users can group test cases into various test suites: 

  • Feature test suites: Test suites contain all test cases belonging to a particular feature
  • Regression test suites: Test suites contain all test cases belonging to multiple features or for the entire application
  • Smoke test suites: Test suites contain basic test cases belonging to a feature, multiple features, or the entire application to perform Sanity testing.

 Check your knowledge with the following interaction:

Test management

PegaUnit framework provides a landing page to manage unit test cases and test suites. Users can perform the following list of activities from the unit testing landing page:

  • View and manage test cases 
  • View history of each test case
  • Export test cases along with their latest test result
  • Filter test cases based on the requirement for easy batch execution
  • View and manage test suites 

Key metrics

PegaUnit framework offers the following two key metrics with respect to test cases: 

  • Test execution summary: Shows the execution metrics of the PegaUnit test cases of the application across various rule types
  • Test compliance: Shows the metrics related to the total number of PegaUnit tests created by users for each supported rule type

CI/CD integration

In the CI/CD pipeline, schedule test cases to run daily in order to analyze and correct test failures early in the cycle. PegaUnit framework offers two Pega APIs (that is, /pegaunits/execute and /pegaunits/execute{ID}/results) as shown in the following image, to execute the application test cases in the pipeline. Users can find these APIs by clicking the Resources button in the Dev Studio and visiting the DevOps section.

Image depicts the PegaUnit framework integration with the CI/CD pipeline.

With the Pega Deployment Manager, users can leverage an in-built task to run PegaUnit test cases. The following image shows the appearance of the task to run PegaUnit test cases in a deployment pipeline using Deployment Manager.  

Image depicts how you can leverage an in-built task to execute PegaUnit test cases with Pega’s Deployment Manager.

This Topic is available 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