Manual compare and deploy
When deploying or validating a package to Salesforce using Gearset, you're able to specify which Apex test classes you want Salesforce to execute as part of validating the package.
When you choose this option, Gearset will list all of the available test classes that are contained in the target org or in the package itself.
Here, because my package included the Apex class named
MyClass, Gearset suggests that I probably want to run
MyClass_T. It has based this on the
_T suffix, which is one of a few patterns used to suggest tests based on naming convention. This selection logic also now applies to Apex Triggers in the package.
The feature to automatically detect relevant tests is actively being developed, with the name-based suggestions being the most recent update. If you encounter any situations where Gearset isn't suggesting a test that you would have expected, please let us know via the in-app chat and we'll make improvements where possible.
Continuous integration jobs
It's also possible to run test more granularly when setting up a CI job. Select the
Specify tests to run option when creating or editing your CI jobs.
Once selected, you can manually define specific test class or suites to run alongside the some of the options that instruct Gearset to add some tests based on the package your CI runs deploy or validate. This will enable you to maximize the chances of running all the relevant tests and achieving acceptable code coverage.
There are two options for getting Gearset to include tests based on the package for your CI job runs:
Tests that reference Apex changes in the deployment
Tests that match naming conventions for Apex changes in the deployment
Let's look at these options and their criteria one by one.
Tests that reference Apex changes
Under this option Gearset will include a test if:
You're making a change to that test in your package
Deploying it as a new test in your package
That test contains a reference to Apex that's changed in your package
When Gearset attempts to provide these test suggestions, it makes a call to the Salesforce API and requests a list of all Apex classes and their associated symbol tables. These tables are used to determine if there are any test classes in the org that have a reference to one of the Apex classes being deployed.
Known issues and limitations
If Salesforce is already compiling Apex when Gearset requests the symbol tables, it will return null. This occasionally results in no tests being suggested, which in turn would mean 0% code coverage and a failed validation.
To mitigate the issue, Gearset retries a number of times (currently 10). There is an increased delay between each try, to avoid any regularly timed compilations that might be happening in the org.
There is no workaround should Gearset reach the end of the retries, but the naming convention test will still apply, as the class names are retrieved even when don't the symbol tables are not received.
Gearset only take account of direct references between the test file and the class it is testing. If you have situations where you expect the inclusion of class
Ato cause test class
Cto be run when
Conly interacts with
Athrough one or more intermediate classes, then a reference to
Awould need to be added to
MyClassis the only class included in a deployment.
IntermediateClassTestsare tests that target
Tests that match the naming convention
In practical terms, making sure that the test class matches the naming convention is one of the easiest ways to ensure that a test class will be suggested.
MyClass is included in the package, the naming convention will include any tests with the following names:
These matches are done case-insensitively, e.g. Gearset will include
These naming conventions apply to Apex classes and Apex triggers. So, for example, if
MyTrigger is included in the package, then having a test named
MyTriggerTests will ensure that the test will be suggested.
Gearset development is guided by our customers, so please let us know if you have any suggestions about how we could improve this feature.