To verify the functionality of your Apex code, Gearset allows you to run your Salesforce unit tests when you deploy changes to your orgs. There are four different test levels you can choose from.

Test levels

  • Default: In a sandbox, no tests are executed. In production, all local tests are executed if your deployment package contains Apex classes or triggers. Local tests are all tests, except those that originate from managed packages. If your deployment package does not contain Apex components, no tests are run.

  • Don't run any tests: No tests are executed, unless you are deploying to production and your deployment package contains Apex classes or triggers, in which case the default tests are run.

  • Run only your tests: All tests in your organisation are run, except those that originate from managed packages.

  • Specify tests to run: Only the tests that you specify are run. You must specify names of test classes in a comma-separated list. Code coverage requirements differ from the default coverage requirements when using this level in production. The executed tests must cover the class(es) or trigger(s) in your deployment package with a minimum of 75% code coverage. This coverage is computed for each class or trigger individually and is different from the overall coverage percentage. The pre-populated apex tests are either in the deployment package or have dependencies in the package.

Specifying the test level in Gearset

  • Validations: To run the default test level, click the main VALIDATE DEPLOYMENT button on the pre-deployment summary. To specify the other test levels, click the arrow to the right of the button and choose the test level for the validation.

  • Deployments: To run the default test level, click the main DEPLOY NOW button on the pre-deployment summary. To specify the other test levels, click the arrow to the right of the button and choose the test level for the validation.

  • Continuous integration: You can set the test level when creating or editing a CI job in the General settings tab. If you make changes to the test level of an existing job, they will be applied the next time the job runs.

    There is the additional option to run Apex tests Gearset suggests based on Apex changes in the package. Here is an article explaining how Gearset selects the tests to run. You can also choose wether you'd like to include tests referencing changes which will run any tests from dependent Apex classes.

    There is also the option to specify test suites to run.

A note on the formatting of test classes for managed packages

If you're needing to run test classes out of a managed package, as part of the deployment of some unmanaged code, you'll need to specify them as "namespacehere.ClassNameHere". Using a period rather than an underscore. This is verified as per this Salesforce documentation.

For more information on Apex unit tests, see this Salesforce Trailhead module on testing: https://trailhead.salesforce.com/en/modules/apex_testing/units/apex_testing_intro

Did this answer your question?