is there a simple way to schedule the run of all test classes? I want to avoid having to do this manually every day.
Thank you!
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityis there a simple way to schedule the run of all test classes? I want to avoid having to do this manually every day.
Thank you!
Here is a cookbook code from developer.force.com that does just that
http://developer.force.com/cookbook/recipe/automated-unit-test-execution
A not so simple way but a good approach if you are using a version control system...
You can go a step further than running your tests once a day by having your tests run every time someone commits a change. See e.g. Setting Up Jenkins for Force.com Continuous Integration. (This also verifies that what you have in your version control system is deployable i.e. pieces are not missing.)
Jenkins listens for changes from your version control system, then when anything changes deploys your code and runs all the tests. On a busy project where many changes are made a day, this allows failures to be identified and addressed more quickly than the following day.
If you are willing to install the Force.com Migration tool and install Jenkins, you can find instructions here for running all of your test classes every night: https://securityzen.net/continuous-integration
I solve my problem following this article: https://www.forcetree.com/2019/12/scheduling-run-all-apex-tests-and.html
global class SelfTest implements Schedulable {
global void execute(SchedulableContext ctx){
List<ApexClass> testClasses = [SELECT Id FROM ApexClass WHERE Name = 'NAME_TEST_CLASS'];
List<ApexTestQueueItem> queueItems = new List<ApexTestQueueItem>();
for (ApexClass testClass : testClasses) {
queueItems.add(new ApexTestQueueItem(ApexClassId=testClass.Id));
}
if(!Test.isRunningTest()) insert queueItems;
}
}
Here's yet another way to do this, with a Visualforce "control panel" that makes setup and monitoring a snap: Force Code's Scheduled Apex Unit Tests
Adding my companies own solution to the mix...
https://github.com/callawaycloud/ScheduledTestRunner
Some high level benefits: