如何为使用通用HTTP请求连接器调用系统层的5种不同资源的集成编写Munit测试用例?

问题描述

我从流程层调用系统层为

先获得:/ abc 得到:/ xyz 帖子:/ efg 在调用此http请求程序之前,通过设置路径,方法和主机,使用通用的http请求程序进行所有这3次调用。

对于每个给我不同响应的呼叫,如何模拟此http请求程序?

解决方法

您可以在Munit中添加3个模拟值。它们每个都有处理器“ http:request”,但具有特定于调用的属性。因此,在每个模拟中,您将提供AttributeName =“ method”和AttributeName =“ path”,其中值对应于您要模拟的特定调用。请参见下面的两个模拟示例。

<munit-tools:mock-when doc:name="Mock when POST" doc:id="8e3b66fe-b5bb-4f96-97b5-8970c1635b12" processor="http:request">
    <munit-tools:with-attributes >
        <munit-tools:with-attribute whereValue="POST" attributeName="method" />
        <munit-tools:with-attribute whereValue="/post" attributeName="path" />
    </munit-tools:with-attributes>
    <munit-tools:then-return >
        <munit-tools:payload value='#[{"data": "post"}]' mediaType="application/json" />
    </munit-tools:then-return>
</munit-tools:mock-when>
<munit-tools:mock-when doc:name="Mock when GET" doc:id="4797dd50-8bc2-428a-9aba-7d03692fc1a2" processor="http:request" >
    <munit-tools:with-attributes >
        <munit-tools:with-attribute whereValue="GET" attributeName="method" />
        <munit-tools:with-attribute whereValue="/get" attributeName="path" />
    </munit-tools:with-attributes>
    <munit-tools:then-return >
        <munit-tools:payload value='#[{"data": "get"}]' mediaType="application/json" />
    </munit-tools:then-return>
</munit-tools:mock-when>

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...