如何解决如何为使用通用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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。