Skip to content

API_MockTestHelper

Class · Group: Web Services

apex
global inherited sharing class API_MockTestHelper

Test helper for API mock verification. Provides assertion methods that delegate to API_MockFactory verification API with descriptive error messages.

Example

apex
API_MockFactory.forService('API_SendEmail').body('{}').statusCode(200).register();
// ... execute callout logic ...
API_MockTestHelper.assertServiceCalled('API_SendEmail');
API_MockTestHelper.assertServiceCalledTimes('API_SendEmail', 1);

See Also: API_MockFactory


Methods

MethodDescription
global static void assertLastRequestContains(String serviceName, String expectedContent)Asserts that the last request body contains the expected text.
global static void assertServiceCalled(String serviceName)Asserts that a service was called at least once.
global static void assertServiceCalledTimes(String serviceName, Integer expectedCount)Asserts that a service was called exactly the specified number of times.
global static void assertServiceNeverCalled(String serviceName)Asserts that a service was never called.

assertLastRequestContains

apex
global static void assertLastRequestContains(String serviceName, String expectedContent)

Asserts that the last request body contains the expected text.

Parameters

ParameterTypeDescription
serviceNameStringThe service class name to verify
expectedContentStringText expected in the last request body

assertServiceCalled

apex
global static void assertServiceCalled(String serviceName)

Asserts that a service was called at least once.

Parameters

ParameterTypeDescription
serviceNameStringThe service class name to verify

assertServiceCalledTimes

apex
global static void assertServiceCalledTimes(String serviceName, Integer expectedCount)

Asserts that a service was called exactly the specified number of times.

Parameters

ParameterTypeDescription
serviceNameStringThe service class name to verify
expectedCountIntegerThe expected number of invocations

assertServiceNeverCalled

apex
global static void assertServiceNeverCalled(String serviceName)

Asserts that a service was never called.

Parameters

ParameterTypeDescription
serviceNameStringThe service class name to verify