1

I am new to the test classes, Trying to write the test class for schedulable class but after reading so many posts still not sure how to cover Execute part of my code. Can anyone please show me the way so that i can try it by my self.

global class PasswordReminders  implements Schedulable {

  List<User> Userlst = [Select Id, email, profileId from User where profile
} 

Test class:-

@isTest 
public class AccRelatedContTest 
{
    static testMethod void testMethod1() 
    {

       insert new Password_Reminder_Threshhold__c(Name = 'FirstReminderThreshold');
       insert new Password_Reminder_Threshhold__c(Reminder_Type__c = 'First Reminder');
       insert new Password_Reminder_Threshhold__c(Upper_Limt__c = 164);
       insert new Password_Reminder_Threshhold__c(Lower_Liit__c = 154);

        Test.StartTest(); 
            PasswordReminders  pre = new PasswordReminders();
            pr.sendEmail();
        Test.StopTest();
    }
}
1
  • Please stop removing your code from the question.
    – Adrian Larson
    Commented Feb 8, 2017 at 11:46

1 Answer 1

1

Here is how you can execute the schedule in your test class. Also make sure to follow best practices (load test data instead of org data, assertions, etc).

Test.startTest();

PasswordReminder pr = new PasswordReminder();
String sch = '0 0 22 * * ?';
system.schedule('Test Password Reminder', sch, pr);

Test.stopTest();
2
  • Is this supposed to be an answer? If so please add some explanatory text. Also note that tests without assertions are frowned upon and kind of miss the point of unit testing.
    – Adrian Larson
    Commented Feb 6, 2017 at 20:30
  • I believe his question was how to execute the schedule in the test. I didn't include anything else (assertions, etc) since it was not part of his question. I updated my answer with some explanation, thanks!
    – Bob Lopez
    Commented Feb 6, 2017 at 20:36

You must log in to answer this question.

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