Today, I discovered ‘by accident’ a brand new Logic Apps feature. It’s the long-awaited mocking functionality, which is currently in preview. Let’s give it a first try!
Exploring the feature
- On every action, there’s now the option Static result, accessible via the “…” menu.
- The Static Result must be enabled on action level.
- You can specify the desired returned Status, Status Code and Headers. What is not available by default, is the Output body, which is maybe the most important one.
- However, via the Switch to JSON Mode icon, you can provide the desired Output body:
- Via a simple request/response, I want to test this feature.
Remark the Erlenmeyer icon, which indicates that the Static Result is activated.
- In Postman, I get the mocked response back:
Feedback
This mocking feature is extremely handy for development purposes and integration testing, in case backend systems are not available.
Typically, you want to use the same Logic Apps template for your integration test, as you use in production. Therefore, you need a way to dynamically enable/disable mocking. The JSON configuration in the code view is shown below. I hoped that I could set the staticResultOptions dynamically at runtime (e.g. via an HTTP header), but this does not pass Logic Apps schema validation. The only option is to set this value at deployment time, via an ARM parameter, for the time being.
The name of the static result refers to a staticResults section, later in the Logic Apps definition. You can specify multiple results. Unfortunately, it’s also not possible to determine at runtime which mock response to return (e.g. via an HTTP header), due to validation errors.
Great feature, with lots of nice possibilities and opportunities. Two improvements I suggest:
- Add the Body by default to the Static Result designer
- Allow more dynamic behavior:
- Allow to decide at runtime whether to mock or not (via default expressions)
- Allow to decide at runtime which response to return (via default expressions)
- Allow dynamic values in the mock response (via default expressions)
Hope this was helpful!
Toon