通过设置静态结果来使用模拟数据测试逻辑应用Test logic apps with mock data by setting up static results

测试逻辑应用时,可能出于各种原因而尚未准备好实际调用或访问应用、服务与系统。When testing your logic apps, you might not be ready to actually call or access apps, services, and systems for various reasons. 通常,在这些情况下,可能需要运行不同的条件路径、强制错误、提供特定的消息响应正文,甚至尝试跳过某些步骤。Usually in these scenarios, you might have to run different condition paths, force errors, provide specific message response bodies, or even try skipping some steps. 针对逻辑应用中的某个操作设置静态结果,可以模拟该操作的输出数据。By setting up static results for an action in your logic app, you can mock output data from that action. 针对某个操作启用静态结果不会运行该操作,而是返回模拟数据。Enabling static results on an action doesn't run the action, but returns the mock data instead.

例如,如果你针对 Outlook 365 中的发送邮件操作设置了静态结果,则逻辑应用引擎只会返回指定为静态结果的模拟数据,而不会调用 Outlook 并发送电子邮件。For example, if you set up static results for the Outlook 365 send mail action, the Logic Apps engine just returns the mock data you specified as static results, rather than call Outlook and send an email.

先决条件Prerequisites

设置静态结果Set up static results

  1. Azure 门户中,在逻辑应用设计器中打开你的逻辑应用(如果尚未打开)。If you haven't already, in the Azure portal, open your logic app in the Logic Apps Designer.

  2. 针对要在其中设置静态结果的操作执行以下步骤:On the action where you want to set up static results, follow these steps:

    1. 在该操作的右上角选择省略号 ( ... ) 按钮,然后选择“静态结果”,例如: In the action's upper-right corner, choose the ellipses (...) button, and select Static result, for example:

      选择“静态结果”>“启用静态结果”

    2. 选择“启用静态结果”。 Choose Enable Static Result. 对于必需的 (*) 属性,请指定要为操作响应返回的模拟输出值。For the required (*) properties, specify the mock output values you want to return for the action's response.

      例如,下面是 HTTP 操作的必需属性:For example, here are the required properties for the HTTP action:

      属性Property 说明Description
      状态Status 要返回的操作状态The action's status to return
      状态代码Status Code 要返回的特定状态代码The specific status code to return
      标头Headers 要返回的标头内容The header content to return

      选择“启用静态结果”

      若要以 JavaScript 对象表示法 (JSON) 格式输入模拟数据,请选择“切换到 JSON 模式”(选择“切换到 JSON 模式”)。To enter the mock data in JavaScript Object Notation (JSON) format, choose Switch to JSON Mode (Choose "Switch to JSON Mode").

    3. 对于可选属性,请打开“选择可选字段”列表,然后选择要模拟的属性。 For optional properties, open the Select optional fields list, and select the properties that you want to mock.

      选择可选属性

  3. 准备好保存时,选择“完成”。 When you're ready to save, choose Done.

    在该操作的右上角,标题栏现在会显示量杯图标(静态结果的图标),表示已启用静态结果。In the action's upper-right corner, the title bar now shows a test beaker icon (Icon for static results), which indicates that you've enabled static results.

    显示已启用静态结果的图标

    若要查找使用模拟数据的先前运行,请参阅本主题稍后的查找使用静态结果的运行To find previous runs that use mock data, see Find runs that use static results later in this topic.

重复使用先前的输出Reuse previous outputs

如果逻辑应用中的某个先前运行包含可重用为模拟输出的输出,则你可以从该运行复制并粘贴这些输出。If your logic app has a previous run with outputs you can reuse as mock outputs, you can copy and paste the outputs from that run.

  1. Azure 门户中,在逻辑应用设计器中打开你的逻辑应用(如果尚未打开)。If you haven't already, in the Azure portal, open your logic app in the Logic Apps Designer.

  2. 在逻辑应用的主菜单中选择“概述” 。On your logic app's main menu, select Overview.

  3. 在“运行历史记录”部分,选择所需的逻辑应用运行。 In the Runs history section, select the logic app run you want.

  4. 在逻辑应用的工作流中,找到并展开包含所需输出的操作。In your logic app's workflow, find and expand the action that has the outputs you want.

  5. 选择“显示原始输出”链接。 Choose the Show raw outputs link.

  6. 复制所需的完整 JavaScript 对象表示法 (JSON) 对象或特定的子节,例如 outputs 节,或者只是 headers 节。Copy either the complete JavaScript Object Notation (JSON) object or the specific subsection you want to use, for example, the outputs section, or even just the headers section.

  7. 遵循设置静态结果中的步骤打开操作的“静态结果”框。Follow the steps for opening the Static result box for your action in Set up static results.

  8. “静态结果”框打开后,选择以下任一步骤: After the Static result box opens, choose either step:

    • 若要粘贴完整的 JSON 对象,请选择“切换到 JSON 模式”(选择“切换到 JSON 模式”):To paste a complete JSON object, choose Switch to JSON Mode (Choose "Switch to JSON Mode"):

      为完整对象选择“切换到 JSON 模式”

    • 若只要粘贴某个 JSON 节,请在该节的标签旁边,选择该节对应的“切换到 JSON 模式”,例如: To paste just a JSON section, next to that section's label, choose Switch to JSON Mode for that section, for example:

      为输出选择“切换到 JSON 模式”

  9. 在 JSON 编辑器中,粘贴前面复制的 JSON。In the JSON editor, paste your previously copied JSON.

    JSON 模式

  10. 完成后,选择“完成” 。When you're finished, choose Done. 或者,若要返回设计器,请选择“切换编辑器模式”(选择“切换编辑器模式”)。Or, to return to the designer, choose Switch Editor Mode (Choose "Switch Editor Mode").

查找使用静态结果的运行Find runs that use static results

在逻辑应用的运行历史记录中,标识其中的操作使用静态结果的运行。Your logic app's runs history identifies the runs where the actions use static results. 若要查找这些运行,请执行以下步骤:To find these runs, follow these steps:

  1. 在逻辑应用的主菜单中选择“概述” 。On your logic app's main menu, select Overview.

  2. 在右窗格中的“运行历史记录”下,找到“静态结果”列。 In the right pane, under Runs history, find the Static Results column.

    包含操作和结果的任何运行的“静态结果”列已设置为“已启用”,例如: Any run that includes actions with results has the Static Results column set to Enabled, for example:

    运行历史记录 -“静态结果”列

  3. 若要查看使用静态结果的操作,请选择“静态结果”列设置为“已启用”的所需运行。 To view actions that use static results, select the run you want where the Static Results column is set to Enabled.

    使用静态结果的操作会显示量杯图标(静态结果的图标),例如:Actions that use static results show the test beaker (Icon for static results) icon, for example:

    运行历史记录 - 使用静态结果的操作

禁用静态结果Disable static results

禁用静态结果不会丢弃最近设置中的值。Turning off static results doesn't throw away the values from your last setup. 因此,下一次启用静态结果时,可以继续使用以前的值。So, when you turn on static results the next time, you can continue using your previous values.

  1. 查找要在其中禁用静态输出的操作。Find the action where you want to disable static outputs. 在该操作的右上角,选择量杯图标(静态结果的图标)。In the action's upper-right corner, choose the test beaker icon (Icon for static results).

    禁用静态结果

  2. 选择“禁用静态结果” > “完成”。Choose Disable Static Result > Done.

    禁用静态结果

参考Reference

有关基础工作流定义中的此项设置的详细信息,请参阅静态结果 - 工作流定义语言的架构参考runtimeConfiguration.staticResult - 运行时配置设置For more information about this setting in your underlying workflow definitions, see Static results - Schema reference for Workflow Definition Language and runtimeConfiguration.staticResult - Runtime configuration settings

后续步骤Next steps