When we want to implement custom Logic with IF/ELSE cases then in many scenarios we use Custom Metadata Types. But when we try to cover it in Test Class, its records can't be inserted like that of a Custom Setting or Custom Object.
You might have stuck in it.Right?
Assume that we have created:
# a custom metadata “youMetadata__mdt” with a picklist field on it “Custom_Field__c”;
# and a custom metadata record with “DeveloperName” value “Default” which we are going to use to determine which calculation to use.
# Also assume that we have created some simple class singhPortal with the following code:
1.) Create a class MetadataCoverage as shown below :
2.) Create its Test Class something like this :
3.) Now finally create the Test class for the main class (singhPortal) i.e singhPortalTest :
The basic test gives 100% coverage. Cheers!!!