Why do unit tests fail?

You may run into an error when attempting to perform unit tests in customer orgs. The exact error message may vary, but it is usually something like this: Requested extension could not be found or is missing field locations!

When FinDock attempts to perform a payment-related action, it tries to determine which payment exstension package is used, which fields are relevent for the action, and so forth. In other words, FinDock expects to have a setup with activated and fully configured packages.

In the context of unit tests, certain parameters that FinDock expects may be missing. We provide some global methods to simulate these parameters in unit tests.

With the following snippet, for example, you can:

  • Activate a source package
  • Activate a payment extension package (in this case, Worldpay)
  • Activates all payment methods for the payment extension
cpm.PaymentHubSource.SourceExtension extension = new cpm.PaymentHubSource.SourceExtension();
CPM.SetupService.install ( extension );
cpm.TestService.activateSourceExtension(extension);
// Activate WorldPay package
wpayc.WorldPayExtensionSetupBase worldpay = new wpayc.WorldPayExtensionSetupBase();
cpm.SetupService.install (worldpay);
cpm.testService.activatePSPExtensionworldpay);
// Activate Payment Methods
list<cpm__Payment_Method__c> payMethods = [select Id, name, cpm__IsActive__c from cpm__Payment_Method__c];
for(cpm__Payment_Method__c payMethod : payMethods){
  payMethod.cpm__Method_Default__c = true;
  payMethod.cpm__IsActive__c = true;
}
update payMethods;

Was this page helpful?