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
linda blinda b 

53% test coverage by not including for loop

Hello, I have this Apex class:


User-added image
and i am missing coverage for the creation of the case object, this is what I have so far, but i am still only at 53% for some reason:

@isTest
private class CaseGenerator_Test{
    static testmethod void testSchduler() 
    {
        Contract__c ctr = new Contract__c();
        ctr.Jamba_Company__c = '0010Y00001YriCE';
        ctr.Price_per_job_posting__c = 800.00;
        if(ctr.Invoice_Type__c != null){
           ctr.Invoice_Type__c = 'Per Unit';
        }
        insert ctr;
        Billing_Unit__c billingUnit = new Billing_Unit__c();
        billingUnit.Contract__c = ctr.Id;
        billingUnit.Invoicing_Date__c = Date.today();
        billingUnit.Name = 'Test BU1';
        insert billingUnit;
        
        Case cse = new Case(
        subject='Rechnung erstellen: '+billingUnit.Name,
        Contract__c=billingUnit.Contract__c,
        Automatically_generated__c=TRUE,
        Billing_Unit__c=billingUnit.Id,
        Status='New');
        insert cse; 
        
        String CRON_EXP = '0 0 0 15 3 ? *';
        Test.startTest();
        String jobId = System.schedule('CaseGenerator',  CRON_EXP, new CaseGenerator());
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
        System.assertEquals(CRON_EXP, ct.CronExpression);
        System.assertEquals(0, ct.TimesTriggered);
        Test.stopTest();
    }
}
Steven NsubugaSteven Nsubuga
@isTest
private class CaseGenerator_Test{
    static testmethod void testSchduler() 
    {
        Contract__c ctr = new Contract__c();
        ctr.Jamba_Company__c = '0010Y00001YriCE';
        ctr.Price_per_job_posting__c = 800.00;
        if(ctr.Invoice_Type__c != null){
           ctr.Invoice_Type__c = 'Per Unit';
        }
        insert ctr;
        Billing_Unit__c billingUnit = new Billing_Unit__c();
        billingUnit.Contract__c = ctr.Id;
        billingUnit.Invoicing_Date__c = Date.today();
        billingUnit.Name = 'Test BU1';
        billingUnit.Unlimited__c = true;
        insert billingUnit;
        
        Case cse = new Case(
        subject='Rechnung erstellen: '+billingUnit.Name,
        Contract__c=billingUnit.Contract__c,
        Automatically_generated__c=TRUE,
        Billing_Unit__c=billingUnit.Id,
        Status='New');
        insert cse; 
        
        String CRON_EXP = '0 0 0 15 3 ? *';
        Test.startTest();
        String jobId = System.schedule('CaseGenerator',  CRON_EXP, new CaseGenerator());
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
        System.assertEquals(CRON_EXP, ct.CronExpression);
        System.assertEquals(0, ct.TimesTriggered);
        Test.stopTest();
    }
}