我正在使用Munit测试我的Mule Flow,并且我使用模拟来设置变量,以便流不会引发异常。当我自己运行测试时,它会通过,但是当我运行我的完整套件时,只是测试失败并且运行调试显示模拟器在作为套件运行时不设置变量。
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mock="http://www.mulesoft.org/schema/mule/mock" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/mock http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd">
<munit:config name="munit" doc:name="MUnit configuration" />
<spring:beans>
<spring:import resource="classpath:endpointproject.xml" />
</spring:beans>
<munit:test
name="test_FilePickUpFlow_CallsFileToStringTransformer_ExactlyOnce"
description="Test">
<flow-ref name="filePickUpFlow" doc:name="filePickUpFlow" />
<mock:verify-call messageProcessor="file:file-to-string-transformer"
times="1" doc:name="Verify Call" />
</munit:test>
<munit:test
name="test_FilePickUpFlow_CallsJsonToObjectTransformer_ExactlyOnce"
description="MUnit Test">
<flow-ref name="filePickUpFlow" doc:name="filePickUpFlow" />
<mock:verify-call messageProcessor="json:json-to-object-transformer"
times="1" doc:name="Verify Call" />
</munit:test>
<munit:test name="test_FilePickUpFlow_CallsJsonParseSubFlow_ExactlyOnce"
description="Validate calls to sub flows are being done properly ">
<set-payload
value="[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]"
doc:name="Set Payload" />
<flow-ref name="filePickUpFlow" doc:name="filePickUpFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
doc:name="Verify Call" times="1">
<mock:with-attributes>
<mock:with-attribute name="name"
whereValue="#[matchContains('jsonParseSubFlow')]" />
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="test_httpInboundFlow_CallsSetPayload_ExactlyOnce"
description="MUnit Test">
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="set-payload"
doc:name="Verify Call" />
</munit:test>
<munit:test
name="test_HttpInboundFlow_CallsJsonToObjectTransformer_ExactlyOnce"
description="MUnit Test">
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params"
value="ParameterMap{[json=[[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]]]}" />
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="json:json-to-object-transformer"
doc:name="Verify Call" times="1" />
</munit:test>
<munit:test name="test_HttpInboundFlow_CallsJsonParseSubFlow_ExactlyOnce"
description="Validate calls to sub flows are being done properly ">
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="#['Set Payload To Query Params']" />
</mock:with-attributes>
<mock:then-return
payload="#['[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]']" />
</mock:when>
<mock:when messageProcessor="json:json-to-object-transformer"
doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['JSON to Object']" />
</mock:with-attributes>
<mock:then-return
payload="#['[{protocol=http, host=0.0.0.0, port=8085, path=, operation=GET}]']" />
</mock:when>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
times="1" doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="name"
whereValue="#[matchContains('jsonParseSubFlow')]" />
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test
name="test_HttpInboundFlow_CallsSetEndpointVariablesSubFlow"
description="MUnit Test">
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="#['Set Payload To Query Params']" />
</mock:with-attributes>
<mock:then-return
payload="#['[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]']" />
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set port variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="port" value="8085" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set path variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="path" value="#[]" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set host variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="host" value="0.0.0.0" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="set protocol variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="protocol" value="http" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="set operation variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="operation" value="GET" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params"
value="ParameterMap{[json=[[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]]]}" />
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="name" whereValue="#[matchContains('setEndpointVariablesSubFlow')]"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="test_HttpInboundFlow_CallsHttpEndpointSubFlow"
description="MUnit Test">
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Set Payload To Query Params']"/>
</mock:with-attributes>
<mock:then-return payload="#['[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]']"/>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set port variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="port" value="8085"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set path variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="path" value="#[]"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set host variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="host" value="0.0.0.0"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set protocol variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="protocol" value="http"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set operation variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="operation" value="GET"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params"
value="ParameterMap{[json=[[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]]]}" />
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="name" whereValue="#[matchContains('httpEndpointSubFlow')]"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
我无法理解为什么测试会因为我在每个套件之间没有通信而有所不同,你知道我怎么能避免这种情况发生吗?
失败的测试是test_HttpInboundFlow_CallsHttpEndpointSubFlow。
答案 0 :(得分:0)
我设法通过更改&#34; test_HttpInboundFlow_CallsJson {arseSubFlow_ExactlyOnce&#34;测试
<munit:test name="test_HttpInboundFlow_CallsJsonParseSubFlow_ExactlyOnce"
description="Validate calls to sub flows are being done properly ">
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Set Payload To Query Params']"/>
</mock:with-attributes>
<mock:then-return payload="#['[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]']"/>
</mock:when>
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params" value="ParameterMap{[json=[[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]]]}"/>
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
times="1" doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="name"
whereValue="#[matchContains('jsonParseSubFlow')]" />
</mock:with-attributes>
</mock:verify-call>
</munit:test>
我不明白为什么这个测试会影响另一个测试,有没有人有任何建议?