You need to sign in to do that
Don't have an account?
sreenath reddy 21
Write a test class for custom meta data
@AuraEnabled(cacheable=true)
public static List<Benefit_Tab__mdt> getBenefitData() {
List<Benefit_Tab__mdt> benefitTab;
try {
if (Benefit_Tab__mdt.sObjectType.getDescribe().isAccessible()) {
benefitTab = [Select Masterlabel,DeveloperName,Tab_Description__c,Category__c,
Order__c,CSS_Class__c,Journey_Steps__c
from Benefit_Tab__mdt
where Category__c = 'International'
order by Order__c];
}
return benefitTab;
} catch (QueryException e) {
throw new AuraHandledException(e.getMessage());
}
}
Can any one please help me to write test class for custom meta data class
public static List<Benefit_Tab__mdt> getBenefitData() {
List<Benefit_Tab__mdt> benefitTab;
try {
if (Benefit_Tab__mdt.sObjectType.getDescribe().isAccessible()) {
benefitTab = [Select Masterlabel,DeveloperName,Tab_Description__c,Category__c,
Order__c,CSS_Class__c,Journey_Steps__c
from Benefit_Tab__mdt
where Category__c = 'International'
order by Order__c];
}
return benefitTab;
} catch (QueryException e) {
throw new AuraHandledException(e.getMessage());
}
}
Can any one please help me to write test class for custom meta data class
Please Replace your apex class with following because I added a logic so that catch part will cover without it we got 75% but with it we got 90% coverage.
I just add only this part. Test Class is following
Let me know if it helps you and marking it as best.
Thank you.
All Answers
It is not necessary for you to create custom metadata in the test class. It is stored as metadata and when you call this method in your test class then the query will return the meta data values. Please see sample test class for custom metadata type here
You can query for custom metadata type in your test class directly like below and get your code covered. I suggest checking
Testing Custom Metadata blog to learn more
Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Please Replace your apex class with following because I added a logic so that catch part will cover without it we got 75% but with it we got 90% coverage.
I just add only this part. Test Class is following
Let me know if it helps you and marking it as best.
Thank you.