+ Start a Discussion
Ermin TsikkosErmin Tsikkos 

Schedulableclass

I have a Schedulableclass which is scheduled to execute every night at 12:00 AM,  here is my class, 


*****
public class appdevDailySnapShot implements Schedulable{
    public List<App_Dev__c> ac {set;get;}    
    public void execute(SchedulableContext con){
        List<App_Dev_Log__c> lstADL = new List<App_Dev_Log__c>();
        try
        {               
           ac=[select Name,Assigned_To__c,Category__c,Completed_date__c,Effort_Hrs__c,Environment__c,Expected_QA_Date__c,In_Progress_Date__c,Old_Create_Date__c,Old_Request__c,On_Hold_date__c,Priority__c,Production_Release_Date__c,Project__c,Ready_for_Production_Release__c,Released_in_QA_Date__c,Released_in_UAT_date__c,Requested_QA_Release_Date__c,Status__c,SVN_update__c,Type__c,Unit_testing_DEV__c,Verified_in_Production__c,Verified_in_QA_Date__c,Verified_in_UAT_date__c from App_Dev__c];            
            for(App_Dev__c adc : ac)
            {
                App_Dev_Log__c AL = new App_Dev_Log__c();
                AL.AD_Request_No__c = adc.Name;
                AL.Assigned_To__c = adc.Assigned_To__c;
                AL.Category__c = adc.Category__c;
                AL.Completed_date__c = adc.Completed_date__c;
                AL.Effort_Hrs__c = adc.Effort_Hrs__c;
                AL.Environment__c = adc.Environment__c;
                AL.Expected_QA_Date__c = adc.Expected_QA_Date__c;
                AL.In_Progress_Date__c = adc.In_Progress_Date__c;
                AL.Old_Create_Date__c = adc.Old_Create_Date__c;
                AL.Old_Request__c = adc.Old_Request__c;
                AL.On_Hold_date__c = adc.On_Hold_date__c;
                AL.Priority__c = adc.Priority__c;
                AL.Production_Release_Date__c = adc.Production_Release_Date__c;
                AL.Project__c = adc.Project__c;
                AL.Ready_for_Production_Release__c = adc.Ready_for_Production_Release__c;
                AL.Released_in_QA_Date__c = adc.Released_in_QA_Date__c;
                AL.Released_in_UAT_date__c = adc.Released_in_UAT_date__c;
                AL.Requested_QA_Release_Date__c = adc.Requested_QA_Release_Date__c;
                AL.Status__c = adc.Status__c;
                AL.SVN_update__c = adc.SVN_update__c;
                AL.Type__c = adc.Type__c;
                AL.Unit_testing_DEV__c = adc.Unit_testing_DEV__c;
                AL.Verified_in_Production__c = adc.Verified_in_Production__c;
                AL.Verified_in_QA_Date__c = adc.Verified_in_QA_Date__c;
                AL.Verified_in_UAT_date__c = adc.Verified_in_UAT_date__c;
                AL.Snapshot_Date__c = date.today();
                AL.Snapshot_Time__c = datetime.now();
                lstADL.add(AL);
            }        
            insert(lstADL);
        }
        catch(Exception pEx){
            System.debug('**** Exception Inserting in APP_DEV_Log ****');
            System.debug(pEx.getMessage());
        }
        finally{
            lstADL.clear();
            lstADL = null;
        }
    }   
}

************

here is my test class,  my code coverage is 22%.

@istest
public class appdevDailySnapShot_Test {
    static testMethod void testSample1(){
        Test.startTest();
        Datetime dt2 = Datetime.now().addMinutes(1);
        String CRON_EXP2 = '0 '+ dt2.minute() + ' * ' + dt2.day() + ' ' + dt2.month() + ' ? ' + dt2.year();
        Id jobId = System.schedule('AppDev Daily Snapshot - Test1', CRON_EXP2, new appdevDailySnapShot());
        Test.stopTest();
        System.assert(jobId != null);
    }
    static testMethod void testSample2() {
        Test.startTest();
        Datetime dt = Datetime.now().addMinutes(1);
        appdevDailySnapShot aObj = new appdevDailySnapShot();
        String CRON_EXP = '0 '+ dt.minute() + ' * ' + dt.day() + ' ' + dt.month() + ' ? ' + dt.year();
        String jobId = System.schedule('AppDev Daily Snapshot - Test2', CRON_EXP, aObj);   
        Test.stopTest();
    }



How to increase the code coverage .. Could you guys please help.
 
JeffreyStevensJeffreyStevens
You have no data in App_Dev__c.  You need to create records in App_Dev__c in your test class.