Automate Unit Tests Execution in Salesforce

Salesforce Jedi
9 min readJun 17, 2023

In Salesforce, it is crucial to have proper control over our unit tests to avoid surprises when deploying our classes to production. Salesforce requires us to create unit tests that cover at least 75% of the code in our class to allow deployment. There are some nuances to this requirement, as we can have the overall coverage from multiple classes compensate for classes with lower coverage by classes with higher coverage, but that is not the focus of this article.

The goal of this article is to create an automated unit test runner in Salesforce. This idea is not originally mine; I learned it from a colleague a long time ago. However, all the code I will provide is my original work, and you have permission to use and modify it to your liking. Having proactive control over our unit tests will prevent us from reacting to test failures when trying to deploy any changes to production.

You can find the complete code here: https://github.com/sfdcjedi/sfdc-automated-tests. From my GitHub repository, you can also deploy this code to your environment with a simple click.

Analysis

First things first, we’re not going to start programming until we know what we’re going to do and how we’re going to do it. At the very least, we need a general idea, a list of problems to solve, and how we’re going to…

--

--

Salesforce Jedi

+7 years in Salesforce landscape, now as architect and tech lead. Take a look to our GitHub repo: https://github.com/sfdcjedi