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
kavya mareedukavya mareedu 

I am really not understanding how to write Test Classes. Please help!!

I have to write a test class for the below schedule apex class, That too with 100% code coverage and system assert equals. How should I start what to do please help me. I really really need all you guys support.

global class DailyPrintbleAndDossierScheduler implements Schedulable
{
    global void execute(SchedulableContext ctx)
    {
        database.executeBatch(new BrokerDataAggregateResultDeleteBatch());
        database.executeBatch(new BrokerDataTopOfficesDeleteBatch());
        database.executeBatch(new BrokerDataSummaryDeleteBatchController());
    }
}

Best Answer chosen by kavya mareedu
Ajay K DubediAjay K Dubedi
Hi kavya,

Try below code:
@isTest
private class DailyPrintbleAndDossierSchedulerTest  {
   @isTest static void DailyPrintbleAndDossierSchedulerTest_method(){
        BrokerDataAggregateResultDeleteBatch brokerObj = new BrokerDataAggregateResultDeleteBatch();
        Test.startTest();
        DailyPrintbleAndDossierScheduler obj = new DailyPrintbleAndDossierScheduler ()
        obj.execute(brokerObj);
        Test.stopTest();
    }
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

All Answers

Tad Aalgaard 3Tad Aalgaard 3
Create a test class and add the following to execute your DailyPrintableAndDossierScheduler class.
 
DailyPrintbleAndDossierScheduler dpads = new DailyPrintbleAndDossierScheduler();
dpads.execute(null);

 
kavya mareedukavya mareedu
If I have to write system asserts also how should I write that???
Tad Aalgaard 3Tad Aalgaard 3
Without being able to see the code behind the three classes you are calling I am unable to answer that question.  If the classes do CRUD operations inserted, updated, deleted or undeleted records then you should test by querying for those records and checking that the changes occurred.
Ajay K DubediAjay K Dubedi
Hi kavya,

Try below code:
@isTest
private class DailyPrintbleAndDossierSchedulerTest  {
   @isTest static void DailyPrintbleAndDossierSchedulerTest_method(){
        BrokerDataAggregateResultDeleteBatch brokerObj = new BrokerDataAggregateResultDeleteBatch();
        Test.startTest();
        DailyPrintbleAndDossierScheduler obj = new DailyPrintbleAndDossierScheduler ()
        obj.execute(brokerObj);
        Test.stopTest();
    }
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
This was selected as the best answer