Test Permission Set Groups with the calculatePermissionSetGroup() Method

Modify and recalculate permission set groups in Apex tests using the calculatePermissionSetGroup() method in the System.Test class. With this method you can force a calculation of aggregate permissions on a permission set group (PermissionSetGroup object) during a deployment.

Where: This change applies to Lightning Experience and Salesforce Classic in all editions.

Why: Permission set group calculations for aggregate permissions are performed after changes are committed. Previously, there was no option to force an immediate calculation of permissions. You weren’t able to easily test permission set groups during deployment as part of an Apex test.

How: The calculatePermissionSetGroup() method can require complex data setup, and each forced recalculation counts against Apex CPU limits. To minimize the number of times you perform this operation in tests, set it to run once in a @testSetup method, and then reuse the resulting data.

https://help.salesforce.com/s/articleView?id=release-notes.rm_forcecom_test_permission_set_groups_apex.htm&release=236&type=5