如何在我的简单测试类中发现错误的原因?

发布于 2025-02-04 16:43:40 字数 1270 浏览 5 评论 0原文

这是我检索双列表框的字段的Aura方法。

@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;
        }

这是我遇到错误的测试类。

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();
}

错误的文本是:

“方法不存在或不正确签名:void getProperties(string)”

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)"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞觅青森が 2025-02-11 16:43:40

您/您的同事定义getProperties(sobject objobject,string sfieldapi),但您正在尝试使用getProperties('isArray'') 。没有1个参数的方法(至少在您粘贴的代码段中没有)。

您可能想用类似

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

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');
沧桑㈠ 2025-02-11 16:43:40

现在,它正在奏效:

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();
}

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文