global with sharing class Batchaccountcountfieldschedule implements Schedulable 
    global void execute(SchedulableContext sc)    
       Batchaccountcountfield bb = new Batchaccountcountfield();

In you test class schedule your class

Batchaccountcountfieldschedule sh1 = new Batchaccountcountfieldschedule();
String sch = '0 0 23 * * ?'; 
system.schedule('Test Territory Check', sch, sh1); 
// add system asserts to check your expected behaviour
  • @Bonny Cool It helped you – Ratan Paul Jan 21 '16 at 5:47
  • 1
    Please don't take this the wrong way, but IMO this is not a test class. This is a 'coverage class'. All it gives you is code coverage to hit the 75% code coverage mark, but it does not test any behaviour. In order for this to be a good test, it needs to make some assertions about the code that's run. In this case, the test should ensure that the batch has run successfully. – mkorman Jan 21 '16 at 9:33
  • Perhaps we should. If someone asks me how to do things the wrong way, I won't give him an answer. I rather explain how to do things the right way. You're not doing anybody a favour if you help them do things wrong. But that's a different discussion altogether :) – mkorman Jan 21 '16 at 11:13

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.