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

Advertisements

2 thoughts on “A first look at the Logic Apps mocking feature

  1. Pingback: Microsoft Integration Weekly Update: March 18, 2019 - BizTalkGurus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s