The .setClientCertificateName
method of the HttpRequest class requires a string that is the name of a certificate in the organization.
In a unit test class, is it possible to mock this method? When I call it in a scratch org (that has no certificates) I get the following exception:
System.CalloutException: Could not find client cert with dev name
@isTest(SeeAllData=true)
on your test? If you get the same exception with that annotation, then I would conclude it's not possible to reference the certificates in a unit test. You also cannot make an actual callout in a unit test (you must use an Http Mock class) so I would not worry about missing any vital functionality by being unable to specify a certificate in your unit test.Test.isRunningTest
method, to set the certificate or not (for example: if I only have the certificate on my production org and it is not available on scratch orgs or sandboxes).Test.isRunningTest()
to be able to fork out the execution flow depending on the running context.