Skip to content

Releases: beyond-the-cloud-dev/http-mock-lib

v1.2.0

26 Dec 21:16

Choose a tag to compare

v1.2.0 - 26-December-2025

Scope

  • New Features: Static Resource Support, Enhanced Request Assertions API
  • Improvements: Global Access Modifier, Parallel Test Execution, Unlocked Package Support

HttpMock

  • Added staticResource() method for loading response body from Static Resources
  • Added requestsTo() method with fluent assertion API for request counting
  • Changed class access from public to global for managed package support
  • Added unlocked package distribution with btcdev namespace

New Features

Static Resource Support

New staticResource() method allows loading response body directly from a Salesforce Static Resource. This is ideal for large or complex response payloads that are difficult to maintain inline.

Example: Mock Using Static Resource

new HttpMock()
    .whenGetOn('/api/v1/users')
    .staticResource('UsersResponseMock')
    .statusCodeOk()
    .mock();

If the Static Resource doesn't exist, a StaticResourceNotFoundException is thrown with a clear error message.

Enhanced Request Assertions API

New requestsTo() method provides a fluent API for asserting the number of HTTP requests made during a test. This replaces the previous getRequestCount() method with a more intuitive interface.

Example: Assert Request Counts

new HttpMock()
    .whenGetOn('/api/v1/authorize')
    .statusCodeOk()
    .whenPostOn('/api/v1/create')
    .statusCodeOk()
    .mock();

Test.startTest();
// Make callouts...
Test.stopTest();

Assert.areEqual(1, HttpMock.requestsTo('/api/v1/authorize').get(), 'One GET request should be made');
Assert.areEqual(1, HttpMock.requestsTo('/api/v1/create').post(), 'One POST request should be made');

Supported Assertion Methods

HttpMock.requestsTo('/endpoint').all();     // Total requests (all methods)
HttpMock.requestsTo('/endpoint').get();     // GET requests
HttpMock.requestsTo('/endpoint').post();    // POST requests
HttpMock.requestsTo('/endpoint').put();     // PUT requests
HttpMock.requestsTo('/endpoint').patch();   // PATCH requests
HttpMock.requestsTo('/endpoint').deletex(); // DELETE requests (x suffix due to reserved keyword)
HttpMock.requestsTo('/endpoint').trace();   // TRACE requests
HttpMock.requestsTo('/endpoint').head();    // HEAD requests

Improvements

Global Access Modifier

The HttpMock class is now declared as global instead of public, enabling usage in managed and unlocked packages.

Parallel Test Execution

Test class now includes @IsTest(IsParallel=true) for faster test execution.

Unlocked Package Support

HTTP Mock Lib is now available as an unlocked package with the btcdev namespace. See the Installation Guide for package installation instructions.

API Version Update

Updated Salesforce API version from 57.0 to 65.0.

Internal Refactoring

  • Renamed interface from HttpMockLib to HttpStubbing
  • All fluent methods now return HttpStubbing interface type
  • Introduced HttpMockRequests inner class for improved request counting
  • Refactored request tracking from method-based to endpoint-based storage
  • Added PMD suppressions for FieldDeclarationsShouldBeAtStart, CognitiveComplexity, CyclomaticComplexity

v1.1.0

29 Jun 13:07

Choose a tag to compare

29-June-2025

This release introduces a major update to the HttpMock library, including breaking changes to the API and a powerful new feature for stacking mock responses.

✨ New Features

Response Stacking

You can now mock multiple responses for the same endpoint. The mock will return the responses in the order they were defined. This is useful for testing scenarios where an initial call might fail, and a subsequent call succeeds.

Example:

new HttpMock()
    .whenGetOn('/api/v1').statusCodeNotFound()
    .whenGetOn('/api/v1').statusCodeOk()
    .mock();

// First callout to /api/v1 will receive a 404 Not Found response.
HttpResponse response1 = new TestApi().makeCallout('GET', '/api/v1');

// Second callout to /api/v1 will receive a 200 OK response.
HttpResponse response2 = new TestApi().makeCallout('GET', '/api/v1');

💥 Breaking Changes

The primary method names for setting up mocks have been changed to improve clarity and readability. The on keyword has been added to the method names.

  • get() is now whenGetOn()
  • post() is now whenPostOn()
  • put() is now whenPutOn()
  • patch() is now whenPatchOn()
  • deletex() is now whenDeleteOn()
  • trace() is now whenTraceOn()
  • head() is now whenHeadOn()

Example:

Old:

new HttpMock().get('/api/v1').statusCodeOk().mock();

New:

new HttpMock().whenGetOn('/api/v1').statusCodeOk().mock();

📦 Other Changes

  • Updated copyright year to 2025.
  • Added assertion messages in test classes for better failure diagnosis.
  • Refactored internal implementation for improved maintainability.

v1.0.0

21 Oct 07:35
b646fc3

Choose a tag to compare

21-October-2024