Automating Salesforce org unit testing

Run your tests daily, track code coverage, and get notified of test failures

Jason Mann avatar
Written by Jason Mann
Updated over a week ago

Unit testing automation jobs in Gearset track Apex unit test results (pass/fail) and code coverage across your chosen orgs on a daily basis. You can configure notifications to be sent if tests start failing or code coverage drops below a set threshold.

Creating a unit testing job in Gearset

Please note, before creating an automated unit testing job, you first need to have added a connection to at least one of your Salesforce orgs.

Once you have at least one org connected, follow these steps:

  1. Navigate to the Unit testing page, found under Automation in the nav menu on the left.

  2. Click ADD NEW JOB....

  3. Choose the days of the week you want the job to run

  4. Choose the time you want the job to run each day.

  5. Give the job a descriptive name (e.g. 'Production tests').

  6. Select the org you want to run the tests on from the drop-down menu.

  7. Specify a minimum % code coverage limit.

  8. (Optional) Specify any namespaces you want to include in the job. By default, unit test jobs will not run tests from managed packages. If you want to run managed package tests, enter their namespaces in this box.

  9. Click Save to create the test job.

Setting job notification preferences

You can configure notifications for your unit test jobs. For example, Gearset can send you an email when your tests start failing. You can set notifications either during job creation, or afterward by clicking Edit job... in the ACTIONS column on the Unit testing dashboard.

Follow these steps:

  1. Select the Notification settings tab.

  2. Choose whether you get notified after every test run, irrespective of the result, or only when tests fail or the level of code coverage has dropped below the specified threshold.

  3. Enter the email address(es) to which you want job status notifications sent.

  4. If required, create additional notifications. Gearset supports SMS notifications (US, UK and Australia only), Slack and Microsoft Teams integration via webhooks, and Chatter integration straight into your org.

  5. Click Save to update your notification settings.

An overview of all your test jobs

All automated unit testing jobs are listed on the Unit testing dashboard. You can see the outcome of the most recent test run (e.g. Tests passed or Tests failed), current code coverage percentage, and the desired level of coverage specified when the job was created:

Viewing test run history for a job

A complete history of all previous runs is maintained for every job. This includes the number of tests run, skipped, passed, failed, and changes in your code coverage. Click on View results to see the daily results and inspect any test failures:

Viewing test failure details

Click View results to see the Test run details page, which lists all tests run, with a breakdown of failed tests and passed tests. Clicking on a failed test displays the error message returned from Salesforce as well as a full stack trace for easier debugging:

Filtering test run history by date

By default, the test run history will display results from the last 30 days. You can change this filtered view by clicking on the date range drop-down menu above the results table.

Find out more about the unit testing in Gearset.

Did this answer your question?