---
schema_version: "1"
id: 9615c1cb04bf59e0783500b23eea6a16866ac11869e2a59af667703a9a82db3f
title: Running a Subset of Tests in a Deployment
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_deploy_run_specific_tests.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_run_specific_tests.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: d2ee5149dddda49af57783b41d819ecfdadd49341a7a26cb3596f6e8c5561b72
description: Test levels enable you to have more control over which tests are run in a deployment. To shorten deployment time to production, run a subset of tests when deploying Apex components. The default test execution behavior in production has also changed. By default, if no test level is specified, no tests are executed, unless your deployment package contains Apex classes or triggers.
---
# Running a Subset of Tests in a Deployment

Test levels enable you to have more control over which tests are run in a deployment. To shorten deployment time to production, run a subset of tests when deploying Apex components. The default test execution behavior in production has also changed. By default, if no test level is specified, no tests are executed, unless your deployment package contains Apex classes or triggers.

If the code coverage of an Apex component in the deployment is less than 75%, the deployment fails. If one of the specified tests fails, the deployment also fails. We recommend that you test your deployment in sandbox first to ensure that the specified tests cover each component sufficiently. Even if your organization’s overall code coverage is 75% or more, the individual coverage of the Apex components being deployed can be less. If the code coverage requirement isn’t met, write more tests and include them in the deployment.

To run a subset of tests, set the RunSpecifiedTests test level on the DeployOptions object. Next, specify each test class to run in DeployOptions. Finally, pass DeployOptions as an argument to the deploy() call. The following example performs those steps to run only the specified test classes.

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

// Set the appropriate test level.
**deployOptions.setTestLevel(TestLevel.RunSpecifiedTests);**

// Specify the test classes to run.
// String array contains test class names.
String\[\] tests = {"TestClass1", "TestClass2", "TestClass3"};
// Add the test class names array to the deployment options.
**deployOptions.setRunTests(tests);**

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

**Notes About Running Specific Tests**

- You can specify only test classes. You can’t specify individual test methods.
- We recommend that you refactor test classes to include the minimum number of tests that meet code coverage requirements. Refactoring your test classes can contribute to shorter test execution times, and as a result, shorter deployment times.
- You can deactivate a trigger in the target organization by deploying it with an inactive state. However, the trigger must have been previously deployed with an active state.

#### See Also

- [Run Relevant Apex Tests in a Deployment (Beta)](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_run_relevant_tests.htm "Use the RunRelevantTests (beta) test level to run only the Apex tests that are relevant to your deployment. Salesforce automatically identifies the relevant tests based on an analysis of the deployment payload and the payload dependencies.")