How to discover the reason for an error in my simple test class?

257 Views Asked by At

This is my aura method to retrieve fields for dual list box.

@AuraEnabled
        public static List <String> getProperties(sObject objObject, string sFieldAPI) {
            List < String > lstOptions = new list < String > ();
            Schema.sObjectType objType = objObject.getSObjectType();
            Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
            map <String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
            list < Schema.PicklistEntry > values =fieldMap.get(sFieldAPI).getDescribe().getPickListValues();
            for (Schema.PicklistEntry a: values) {
            lstOptions.add(a.getValue());
            }
            lstOptions.sort();
            return lstOptions;
        }

And this is the test class where I'm getting error.

testMethod static void testGetProperties(){
    setupInsertData();
    Test.startTest();
    List<String> Prop = MessageTypeController.getProperties('isArray');
    System.debug('Test Category'+Prop);
    if(Prop!=null){
          System.assertEquals(Prop!=null,true);
    }else{
         System.assertEquals(Prop==null,true);  
    }
    Test.stopTest();
}

The text of the error is:

"Method does not exist or incorrect signature: void getProperties(String)"

2

There are 2 best solutions below

4
On

With this now it's working:

testMethod static void testGetProperties(){
    setupInsertData();
    Test.startTest();
    skyvvasolutions__MessageType__c msg = new skyvvasolutions__MessageType__c();
    List<String> Prop = MessageTypeController.getProperties(msg, 'skyvvasolutions__Properties__c');
    System.debug('Test Category'+Prop);
    if(Prop!=null){
          System.assertEquals(Prop!=null,true);
    }else{
         System.assertEquals(Prop==null,true);  
    }
    Test.stopTest();
}
1
On

You / your colleague defined getProperties(sObject objObject, string sFieldAPI) but you're trying to call it with getProperties('isArray'). There's no method with 1 parameter (at least not in the code snippet you pasted).

You probably want to call it with something like

MessageTypeController.getProperties(new Opportunity(), 'StageName');