0

I have a static method for which I am trying to write a test class for.

public with sharing class CDX_OrderSearchScreenController{

public class StandingOrdersWrapper{

//Variable declarations

public StandingOrdersWrapper(CDX_Staging_Order__c stagingRecord)
{
  //Code
}
}

@AuraEnabled(cacheable=true)
//Need to Write a Test class for this method
    public static List<StandingOrdersWrapper> getStandingOrders(Id stagingId, String stagingRecordData) {
//code
}
}

The Test class I have is follows

@isTest
public  class CDX_OrderSearchScreenController_Test {
@isTest
    public static void getStandingOrdersTest_1()
    {
       List<CDX_OrderSearchScreenController.StandingOrdersWrapper> standingOrders; 

       CDX_Staging_Order__c testRecord = new CDX_Staging_Order__c(Name = 'Test Data', CDX_Date_of_Message__c = Date.newInstance(2020, 01, 10));
insert testRecord; 

       standingOrders = CDX_OrderSearchScreenController.getStandingOrders(testRecord.Id, JSON.serialize(testRecord)); 
    }
}
}

The above code is not covering the method at all. What am I doing wrong?

1 Answer 1

1

It probably has to do with the code related to getStandingOrders. If you are not using the constructor then the line won't be covered.

You can either provide more details about your code or change the getStandingOrders method (just as a test) to something like:

@AuraEnabled(cacheable = true)
//Need to Write a Test class for this method
public static List < StandingOrdersWrapper > getStandingOrders(Id stagingId, String stagingRecordData) {
    //code
    CDX_Staging_Order__c testStagingOrder = [SELECT Id FROM CDX_Staging_Order__c LIMIT 1]; //Assuming you have CDX_Staging_Order__c records on your ORG;
    return new List<StandingOrdersWrapper>{new StandingOrdersWrapper(testStagingOrder)};
}

And then run the tests again to confirm the constructor is also covered.

Best regards!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .