Delete Metadata Step and Test Level in deployments

When working with the destructive changes feature, you will notice that, apart from the Git Promotion step, a Delete Metadata step is created in the deployment record. 

User-added image

Git Promotion Step:

This is the step that will make the changes in Git and deploy components in the destination org. This step will not make any deletions in the destination org.
The Test Level on this step can be defined in the following ways:
  1. When creating the Deployment record from the Promotion record. The test level selected there will be applied to all the steps in the deployment record created.
  2. With the "Promotion Test Level" field on the user story if the checkbox "Promote & Deploy" is used.
  3. By changing the Test Level directly in the Git Promotion Step in the Deployment record.

If the Test Level on the Git Promotion step is set to RunSpecifiedTest, the test classes that will run when deploying will be those in the list of components in the deployment or those specified in the "Test Classes" attachment in the deployment record if the button Add Test Classes was used in the user stories.

Delete Metadata Step:

The only purpose of this step is to delete in the destination org the metadata components that were selected in the destructive changes commit.
The Test Level on this step can be defined in the following ways:
  1. When creating the Deployment record from the Promotion record. The test level selected there will be applied to all the steps in the deployment record created.
  2. With the promotion Test level field on the user story if the checkbox "Promote & Deploy" is used.
  3. By changing the Test Level directly in the Git Promotion Step in the Deployment record. This will required some manual steps since there is no field in the VF page that allows you to change the test level. 
    1. Copy the deployment record Id
    2. Go to the home tab.
    3. Remove home/home.jsp from the url.
    4. Paste DeploymentId?nooverride
    5. You are now in the standard layout for Deployment record, overriding the Visualforce page.
    6. In the Steps related list, click on the Delete Metadata step name.
    7. In this page you will see a text field called "dataJson". This field contains the test level for the Delete Metadata Step. The options are:
  • {"testLevel":"NoTestRun"}
  • {"testLevel":"RunSpecifiedTests"}
  • {"testLevel":"RunLocalTests"}
  • {"testLevel":"RunAllTestsInOrg"}
User-added image

If the Test Level on the Delete Metadata step is set to "RunSpecifiedTest", the test classes that will run when deploying will be those specified in the "Test Classes" attachment in the Delete Metadata step. This file must be created and attached manually in the Delete Metadata Step record. You can access this record following the steps mentioned above.

User-added image

This is an example of the content in the Test Classes attachment. 

[{"n":"CourseManagerTest"},{"n":"AppleWatchTest"}]

Considerations when working with Delete Metadata Steps.

1. If the test level selected is "Run Specified Test" but the "Test Classes" attachment doesn't exist in the Delete Metadata step, Salesforce will not allow the deployment and it will return this error:

"INVALID_OPERATION: runTests must not be empty when a testLevel of RunSpecifiedTests is used"

2. If the test level selected is "No Test Run" and you are deploying to Production, Salesforce will not allow the deployment and it will return this error:

"INVALID_OPERATION: testLevel of NoTestRun cannot be used in production organizations"

In any of the 2 scenarios above, before the deployment fails, Copado will change the test level automatically to "Run All Tests" and will try the deployment again.

When this happens, you will see a message similar to this one in the deployment results:

"Modified deployment test level. Old value: 'RunSpecifiedTests', New value: 'RunAllTestsInOrg'. Reason:  'You must provide at least one test to run'"

User-added image



 

How did we do?