Skip to main content

Setting Apex test levels

A guide to running tests when deploying with Gearset

Written by Jacob Joshua

Gearset can run your Salesforce unit tests when you deploy changes to your orgs, so you can verify your Apex code before it reaches the target org. Use this article to pick a test level and set it for a manual deployment or a CI job.

What are the Apex test levels?

Gearset runs a different set of Apex tests at each test level. The following table shows which tests each level runs, and the code coverage each level requires.

Test level

Which tests run

Coverage requirement

Salesforce default tests

In a sandbox, none.

In production, all local tests run if your deployment package contains Apex classes, triggers, or Flows set to activate on deployment. Local tests exclude tests from managed packages. If your package contains none of those, no tests run.

In production, 75% overall Apex code coverage, and every test that runs must pass. A single failed test fails the deployment, even at above 75% coverage.

Relevant Tests

Salesforce selects the tests, based on the components in the deployment.

75% overall Apex code coverage

All your tests

Every test in your org. Including tests from Managed Packages.

75% overall Apex code coverage

Don't run any tests

None, unless you deploy to production and your package contains Apex classes, triggers, or Flows set to activate on deployment. In that case, Salesforce default tests run instead.

When Salesforce default tests run, at least 75% overall Apex code coverage

Specify tests to run (manual compare and deploy)

The test classes you specify.

In production, each Apex class or trigger in the deployment package needs at least 75% coverage individually.

Choose tests to run and fine-tune on individual PRs in your pipeline (CI and Pipelines)

Tests configured for the job, including any enabled automatic test selection, plus tests specified on individual PRs.

In production, each Apex class or trigger in the deployment package needs at least 75% coverage individually.

Only run the tests specified on individual PRs in your pipeline (CI and Pipelines only)

Only PR-specified Apex tests are run, nothing else.

See "Only run the tests specified.." below for more info.

In production, each Apex class or trigger in the deployment package needs at least 75% coverage individually.

How do I set the test level in Gearset?

You set the Apex test level in two places depending on what feature you are using:

Manual compare and deploy

  • Validations: To run the default test level, click the main Validate deployment button on the pre-deployment summary. To choose another level, click the arrow beside the button.
    ​

  • Deployment: Click Deploy Now to use the default test level. To choose another level, click the arrow beside the button.

Specify tests to run

Choose Specify tests to run to select individual Apex test classes. Enter multiple class names as a comma-separated list.

Gearset pre-populates tests included in the deployment package or identified through dependencies. Review the selection before validating or deploying.

For more on how Gearset identifies tests, see Gearset suggested Apex tests.

Note: UI tests are triggered after a successful deployment. Gearset does not show the results, so check your provider for details.

Continuous integration and Pipelines

You can set the test level when creating or editing a CI job in the Test settings tab. Changes apply the next time the job runs.
​

When you select Choose tests to run and fine-tune on individual PRs in your pipeline, additional test selection options appear.This will enable you to maximize the chances of running all the relevant tests and achieving acceptable code coverage.
​

  • Test classes and test suites: Define a manual list of individual test classes or test suites to run. Separate each test class or suite name with a comma.

  • Tests that reference Apex changes: Run tests that have a compile-time reference to the Apex changes in each CI job run's package. Apex tests you change or add in the package are included too.

  • Tests that match naming conventions: Run tests whose names match the naming conventions of the Apex changes in each CI job run's package.

  • Tests that are in the deployment: Run every Apex test class included in the deployment package.

For more on the last two options, see Gearset suggested Apex tests.

Only run tests specified on individual PRs

Select Only run the tests specified on individual PRs in your pipeline in your CI job’s Test settings to run only the Apex tests specified on your pull requests.

Use this option when dependency-based or naming-convention-based selection includes more tests than you need. Gearset won’t automatically add other tests.

Important: If a PR contains Apex or Flow changes and no tests have been specified, validation and deployment runs fail before Gearset sends the deployment package to Salesforce. Specify tests on the PR before retrying the run.

How does Relevant Tests behave in CI jobs?

Relevant Tests uses Salesforce’s test selection, not Gearset’s suggested-tests logic. Specified tests on individual PRs aren’t included, and changing which tests Salesforce selects may require code annotations or changes to your test classes.

This setting requires Salesforce API version 66 or later. At API version 65 or lower, Gearset fails the run rather than falling back to another test level. To resolve this, update either:

  • Your metadata filter to API version 66 or later, or to Highest common version.

  • Your VCS API version to 66 or later. Read the linked guidance before making this change.

To include tests specified on individual PRs, choose Choose tests to run and fine-tune on individual PRs in your pipeline or Only run the tests specified on individual PRs in your pipeline instead.

How do I format test class names for managed packages?

To run test classes from a managed package as part of a deployment of unmanaged code, specify each one as namespacehere.ClassNameHere. Use a period, not an underscore. Salesforce's deployment documentation confirms that a class name can include a namespace in dot notation.

For more on Apex unit tests, see Salesforce's Apex testing Trailhead module.

Did this answer your question?