Mock outbound HttpClient web service calls during testing
Important
Some of the functionality described in this release plan has not been released. Delivery timelines may change and projected functionality may not be released (see Microsoft policy). Learn more: What's new and planned
Enabled for | Public preview | General availability |
---|---|---|
Admins, makers, marketers, or analysts, automatically | Apr 2025 | Apr 2025 |
Business value
To allow for easier testability of AL code that includes outbound web service calls, we're introducing the ability to mock such calls. This allows the developer to hardcode return values to the calling code during tests, without actually performing the outbound web service call. The ability to mock calls is especially valuable when testing Copilot and AI features, as developers can write unit tests for these without actually connecting to Azure OpenAI Service, and thereby save any unnecessary token consumption.
Feature details
AL developers will be able to easily mock out HttpClient Get/Put/Delete/Post calls in unit tests. The idea is to allow easy substitutions of the responses of HttpClient calls in unit tests by introducing a new handler function to intercept HttpClient calls.
The signature is expected to be:
[HttpClientHandler]
procedure MyHandler(path: Text/Uri; requestType: HttpRequestType; var response: TestHttpResponseMessage; var success: Boolean): boolean
The default behavior will be to prevent making an actual request, but there should be the option to do so by changing the exit value.
Tell us what you think
Help us improve Dynamics 365 Business Central by discussing ideas, providing suggestions, and giving feedback. Use the forum at https://aka.ms/bcideas.