Salesforce deployments with 海角天涯社区 can be up to 12x faster than with first-party tools, and we鈥檙e constantly making even more improvements to streamline your deployments and save even more of your time and effort. Currently, we鈥檙e piloting new functionality that automatically suggests which unit tests you should run when you manually deploy or validate a package in Gearset. This improvement will make test selection and testing quicker and easier. It should also save lots of teams from needing to track their unit tests outside of Gearset.
The importance of unit testing
We all know that Apex code can鈥檛 be developed in production. Apex classes and their test classes must be written in a developer environment and then deployed to production. Salesforce encourages unit testing and requires that your test coverage is at least 75%. If your code coverage falls below this threshold, Salesforce will not allow you to deploy to that org. Many Salesforce teams sensibly strive for better code coverage than 75%, and adopting a process is a good way to do this.
Using 海角天涯社区, you can set up unit testing jobs that automatically run the unit tests in an org every day. Automated unit testing allows you to track code coverage and alerts you to any tests that fail. 海角天涯社区 also enables you to run unit tests during deployments to make sure that your deployment doesn鈥檛 break any tests. It鈥檚 better to understand your deployment package鈥檚 impact on your tests before deploying.
Salesforce DevOps in the age of AI: is your custom pipeline ready?
Running the right tests
When running unit tests during a deployment, you want to strike a balance. On the one hand, you need to run enough tests to cover the changes in the deployment package. On the other hand, you don鈥檛 want to slow down your deployment. Running all of your tests is an obvious way to make sure you鈥檝e covered everything, but that can take a very long time - particularly if you have thousands of unit tests in your org. And most of those tests won鈥檛 be necessary to run with each deployment, so you鈥檙e needlessly wasting time.
Ideally, you identify the right tests to run during the deployment and only run those tests. Different sets of metadata changes will affect different tests, so working out which tests to run is something that needs to happen for each and every deployment package - and that鈥檚 a challenge.
Manually selecting tests
Until recently, the only solution in 海角天涯社区 has been to choose tests manually, either by selecting from a list of all the unit tests in your deployment package and target org, or by entering a comma-separated list of all the tests you鈥檇 like to run.
Searching through a full list of tests wasn鈥檛 a great option for teams with a huge number of tests. For this reason, many of 海角天涯社区鈥檚 users preferred to specify tests using the textbox, and we have kept this option available alongside the improvement we鈥檝e made. Just click on Manually specify tests and type or paste in the names of the test classes you want to run.
In many cases, teams have been maintaining a spreadsheet that maps out all their unit tests, using this spreadsheet to determine which tests they鈥檒l need to run for each deployment. Some users have lists of commonly used tests that they use as templates they can paste into the textbox.
Many teams follow naming conventions for tests, for example, adding Test as a prefix or suffix to the name of the Apex class being tested. This can help to identify the tests that need to be run. But both of these methods for specifying tests involve manual work and take up time and brainpower. And needing to refer to lists of tests stored outside of 海角天涯社区 doesn鈥檛 help to streamline the deployment process. For all of these reasons, we鈥檝e worked on a new and improved way for you to select tests.
Automatic test selection
Our recent updates to this part of the 海角天涯社区 app make the test selection process much easier. Where you used to see all the tests in your deployment package and target org in one long list, you鈥檒l now see this has been split in two: a list of preselected tests that 海角天涯社区 suggests you run; then the rest of your tests listed below, which by default are not selected.
The list of suggested tests is automatically generated based on the metadata in your deployment package. As well as any test classes in your package, 海角天涯社区 also suggests you run tests that call any Apex classes in your deployment package. It only suggests test classes that have direct dependencies in your package, so chains of dependent tests won鈥檛 all be suggested. There may be additional tests you know you want to include, which you can do easily. This smart new functionality will save you from having to work out each and every test you should run and selecting them or pasting in a list of tests.
How to use automatic test selection
As before, you can select which tests to run by clicking on the arrow button next to either the Deploy now or Validate deployment button. Then click Specify tests to run.
You can review the list of suggested tests and, if you feel it necessary, amend the selections if you prefer. You can deselect suggested tests and select other tests from the list below. Use the search bar to track down the tests you鈥檙e looking for.
In the example shown above, 海角天涯社区 has picked up that the tests PasswordControllerTest, AccountSetupTest and ValidateUserTest are either in the deployment package or have dependencies in the package. Once you鈥檙e ready to deploy or validate your package and run these tests, clicking Run tests will begin the deployment or validation.
Get started today
If you鈥檙e looking to implement Salesforce testing best practices with 海角天涯社区鈥檚 automatic unit testing solution, you can start a today.