Newer Version Available
Run the Same Tests in Sandbox and Production Deployments
Starting in API version 34.0, you can choose which tests to run in your development
environment, such as only local tests, to match the tests run in production. In earlier versions,
if you enabled tests in your sandbox deployment, you couldn’t exclude managed package
tests.
By default, no tests are run in a deployment to a non-production organization, such as a sandbox or a Developer Edition organization. To specify tests to run in your development environment, set a testLevel deployment option. For example, to run local tests in a deployment and to exclude managed package tests, set testLevel on the DeployOptions object to TestLevel.RunLocalTests. Next, pass this object as an argument to the deploy() call as follows.
1// Create the DeployOptions object.
2DeployOptions deployOptions = new DeployOptions();
3
4// Set the appropriate test level.
5deployOptions.setTestLevel(TestLevel.RunLocalTests);
6
7// Call deploy() by passing the deployment options object as an argument.
8AsyncResult asyncResult = metadatabinding.deploy(zipBytes,deployOptions);