10

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!

1
  • consider using a vendor DevOps tool: Copado, Gearset, Flosum, Blue Canvas - this is a basic feature of those tools plus you get so much more
    – cropredy
    Jun 28, 2022 at 22:35

6 Answers 6

12

Here is a cookbook code from developer.force.com that does just that

http://developer.force.com/cookbook/recipe/automated-unit-test-execution

1
  • Thank you! I will follow this and see if I can implement it. I was hoping there's something that won't require custom coding :-(
    – user9862
    Aug 6, 2014 at 13:19
3

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.

2
  • we haven't implemented version control yet. I need an interim solution until version control process is in place.
    – user9862
    Aug 6, 2014 at 13:20
  • @user9862 Understood - just wanted to paint the picture of what the overall setup could look like in the future.
    – Keith C
    Aug 6, 2014 at 13:22
1

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

1

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;    
    }
}
0

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

enter image description here

2
  • Steve, how do I install this automation?
    – vlr
    Mar 14, 2018 at 20:23
  • I added everything to my org, but I can not find this section above when you could schedule the time and specify unit test prefix. I have only these tabs: "Automated Test Setup" and "Automated Test Runs." Automated Test Setup has only fixed times for TestRunner and for TestRunnerResults.
    – vlr
    Mar 20, 2018 at 20:01
0

Adding my companies own solution to the mix...

https://github.com/callawaycloud/ScheduledTestRunner

Some high level benefits:

  • Installable Unlocked Package
  • Flexible notifications
  • Runs on Salesforce (no need to auth with 3rd party)
  • Stores Test Results
  • Tracks "First Failure"
  • Generates Audit Trail Query

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .