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
JoshTonksJoshTonks 

Apex Test Class with Aggregate Values Currently 0 Coverage but has a tick on status in the Console

I have an apex class which gets the values of device quantites coming up in the next few days. Im trying to build a display board with visualforce which works.

Im struggling to write a test class which covers the line however the test class is getting a tick in the status in the test logs on the developer console.

This is my class
 
public class LogisticsQuantity {
//Main class
    Date STARTDAY = Date.today();
    Date ENDDAY = STARTDAY.addDays(5);
    public Summary[] Summaries { get; set; }
    public LogisticsQuantity() {
        AggregateResult[] results = [
            SELECT Last_Date_for_Dispatch__c, Count(Id),
            SUM(Hard_Wired_Dash_Camera__c) hard,
            SUM(New_Unit_Qty__c) newUnit,
            SUM(Service_Unit_Qty__c) service
            FROM Unit_Request__c
            WHERE Last_Date_for_Dispatch__c >= :STARTDAY AND Last_Date_for_Dispatch__c < :ENDDAY AND Picked__c = FALSE
            GROUP BY Last_Date_for_Dispatch__c
            ORDER BY Last_Date_for_Dispatch__c ASC NULLS LAST
        ];
        Summaries = new List<Summary>();
        for (AggregateResult ar : results) {
            Summaries.add(new Summary(ar));
        }
    }

    // wrapper class for aggregate data
    public class Summary {
        public decimal NewQuantity { get; set; }
        public decimal SvcQuantity { get; set; }
        public decimal CamQuantity { get; set; }
        public date Name { get; set; }

        public Summary(AggregateResult ar) {
            CamQuantity = (decimal) ar.get('hard');
            NewQuantity = (decimal) ar.get('newUnit');
            SvcQuantity = (decimal) ar.get('service');
            Name = (date) ar.get('Last_Date_for_Dispatch__c');

        }
    }

}

My test class is looking like this im certain i must be missing something from it as im getting code coverage 0
@isTest
public class LogisticsQuantityTest {

    Date TODAY = Date.today();
    
    static testMethod void testLogsticsQuantity() {
    
    Unit_Request__c UR = new Unit_Request__c();
    UR.Date_Of_Job__c = Date.newInstance(2019,12,01);
    UR.Telenor_Elder__c = TRUE;
    UR.Company_Name_Text__c = 'Test Account';
    UR.Contact_Name_Text__c = 'Test Contact';
    UR.Contact_Telephone_Number__c = '01234456789';
    UR.Contact_Email_Address__c = 'test@test.com';
    UR.Unit_Request_to_Case__c = '5008E00000GEaqt';
    UR.LMU_2630_Loom_Standard__c = 1;
    UR.LMU_2630_Loom_Standard__c = 1;
    
    insert UR;
    test.startTest();
}
}

​​​​​​​
Gian Piere VallejosGian Piere Vallejos
Hello,

I'm affraid that you are not calling the "LogisticsQuantity" class from your test, that's why you are not getting coverage. Otherwise, if you are trying to test a Visualforce Page Controller you need to use Page References. You can get more information about how to test VFPs in the next link: Testing Custom Controllers and Controller Extensions (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm" target="_blank)