A first look at the Logic Apps mocking feature

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.

Mocking1

  • The Static Result must be enabled on action level.

Mocking2

  • 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.

Mocking3

  • However, via the Switch to JSON Mode icon, you can provide the desired Output body:

Mocking4

  • Via a simple request/response, I want to test this feature.
    Remark the Erlenmeyer icon, which indicates that the Static Result is activated.

Mocking5

  • In Postman, I get the mocked response back:

Mocking6

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.

Mocking7

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.

Mocking8

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

About me

Hi! I’m Toon Vanhoutte, a hands-on Azure architect – based in Belgium – with a big passion for teaching and helping people out. I’m happy to assist you during your Azure journey with high-quality advisory and I would love to teach you Azure’s possibilities via my tailored training courses.

Subscribe to the blog