function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
v varaprasadv varaprasad 

test class for schedule apex

Hi All ,

   i am writing test class for following schedule class 
      global class scheduleAccountWriteXML implements Schedulable{
    // Execute method
    global void execute(SchedulableContext SC) {
// Code to be executed when the schedule class wakes up

            String CRON_EXP = '0 0 * * * ?';
            string jobName = 'Account_Interface_Schedule_job_that_runs_every_1_hour_for_Accounts'; 
            scheduleAccountWriteXML p = new scheduleAccountWriteXML();
            system.schedule(jobName, CRON_EXP, p);              
        Catch (Exception e){            
            Messaging.SingleEmailMessage emailMessage = new Messaging.SingleEmailMessage();
            emailMessage.setToAddresses(new String[] { ''});
            Messaging.SendEmailResult[] emailResult = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { emailMessage}, true);

I received code 90%,but test execution will be fail .

public class Test_scheduleAccountWriteXML {
    public static testmethod void testaccountxml(){
            String CRON_EXP = '0 0 * * * ?';           
            scheduleAccountWriteXML scc6= new scheduleAccountWriteXML();       
            String jobid = system.schedule('varam', CRON_EXP, scc6);  

Any help please.

Take a look at this [1]  and let me know if this helps you.  You're going to have a tough time doing a real test because you can't see what the content of your email is.  But at least you can look at the Limits.getEmailInvocations() to see if you did send an email.