0

I have written Test classes for my APEX Classes. I want to automate these Test suite to be run daily at 8:00 AM for an example. How can I achieve that? Can I use schedulable apex class where I call all the test classes to run it and schedule at my preferred time or do I need a crone job kind of thing to schedule at?

I would appreciate any kind of idea or help.

0

I tried to implement the schedulable interface with @isTest class and it works fine with test class so you can use that with cron expression.

But, I don't think it will work as expected because test class is not considered in apex code limit. The other point is if you implement schedulable with test class then again you have to write the test class for the test class and it will go into a loop.

So, I don't think you can run test class at a particular time.

You can go with this link also for the implementation.

https://success.salesforce.com/ideaView?id=08730000000HlPT

|improve this answer|||||
  • Thanks @Ram. Even I thought of the same as I will write test class for the schedulable class. Let me check in the link you provided. – Sagar Hinsu Oct 31 '17 at 10:30
1

In a project we've used Gearset to schedule tests. It can send you an email with the results and the % of test coverage. It can do a whole range of other stuff too, but the free version at least supports test scheduling.

Here's a Youtube video they made explaining how it works

PS. I don't work for Gearset

|improve this answer|||||
  • Thanks. Let me try with that. Though I have used gearset but for different purpose. – Sagar Hinsu Nov 2 '17 at 5:32
  • @Sagar What did you think of it? Does it solve your use case? – Folkert Nov 10 '17 at 10:10
  • I created one schedulable class and create an automation which runs all the test class and send email to all the devs with Pass/fail per class and per method. – Sagar Hinsu Nov 10 '17 at 11:14
0

You could try setting up sfdx for your organization, and use the force:apex:test:run command to get your code coverage at any given time. The tricky part would be writing a script to run on your system at a given time, plus figuring out how to report the coverage.

You can read more about sfdx here.

What is it?

The Salesforce DX CLI is a powerful command line interface that simplifies development and build automation when working with your Salesforce org. Use it to:

  • Aggregate all the tools you need to develop with and perform commands against your Salesforce org
  • Synchronize source to and from scratch orgs
  • Create and manage orgs
  • Import and export data
  • Create and execute tests
  • Create and install packages

You can learn more about setting up sfdx here.


Once set up, running this command will return your org's code coverage:

$ sfdx force:apex:test:run -c

You can learn more about running tasks daily here:

  1. MacOS: How can I get a script to run everyday?
  2. Windows: MSDN: SCheduling Tasks
|improve this answer|||||
  • Thanks @battery.cord.. I was not aware of sfdx. interesting thing to learn. – Sagar Hinsu Nov 2 '17 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.