Run Local Tests in a Sandbox Deployment

You can now choose which tests to run in sandbox deployments to match the test run behavior in production. Previously, if you enabled tests in your sandbox deployment, you couldn’t exclude managed package tests.

As part of this change, the runAllTests deployment option has been replaced with testLevel. For a description of all test levels that you can use in your development environment, see test levels for the deploy() call. For example, to run local tests in a deployment and to exclude managed package tests, set testLevel to the RunLocalTests value.



The RunLocalTests test level is enforced regardless of the contents of the deployment package. In contrast, tests are executed by default in production only if your deployment package contains Apex classes or triggers. You can use RunLocalTests for sandbox and production deployments.

If you’re using the Migration Tool, add the testLevel="RunLocalTests" parameter to the deploy target, as shown in this example.

<target name="deployCode">
    <sf:deploy username="${sf.username}" password="${sf.password}" 
           sessionId="${sf.sessionId}" serverurl="${sf.serverurl}"
           deployroot="codepkg" testLevel="RunLocalTests">

If you’re using Metadata API, set the test level on the DeployOptions object to TestLevel.RunLocalTests and then pass this object as an argument to the deploy() call as follows.

// Create the DeployOptions object.
DeployOptions deployOptions = new DeployOptions();

// Set the appropriate test level.

// Call deploy() by passing the deployment options object as an argument. 
AsyncResult asyncResult = metadatabinding.deploy(zipBytes,deployOptions);