-1
我在類FirstMockTest
下面的代碼similiart一個例子從書Camel in Action
:Apache的駱駝單元測試模擬sideffect
String msg1 = "Camel Msg1";
String msg2 = "Camel Msg2";
String msg3 = "Camel Msg3";
String msg4 = "Camel Msg4";
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jms:topic:quote").to("mock:quote");
from("jms:topic:quote2").to("mock:quote2");
}
};
}
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
//fake jms register
context.addComponent("jms", context.getComponent("seda"));
return context;
}
@Test
public void testMultipleBodies() throws InterruptedException {
MockEndpoint quote = getMockEndpoint("mock:quote");
template.sendBody("jms:topic:quote", msg1);
template.sendBody("jms:topic:quote", msg2);
quote.expectedBodiesReceived(msg1, msg2);
quote.assertIsSatisfied();
}
@Test
public void testMultipleBodies2() throws InterruptedException {
MockEndpoint quote2 = getMockEndpoint("mock:quote2");
template.sendBody("jms:topic:quote2", msg3);
template.sendBody("jms:topic:quote2", msg4);
quote2.expectedBodiesReceived(msg3, msg4);
quote2.assertIsSatisfied();
}
當運行gradle clean test --tests FirstMockTest
我得到以下 單元測試錯誤輸出:
FirstMockTest > testMultipleBodies2 FAILED
java.lang.AssertionError: mock://quote2 Body of message: 0.
Expected: <Camel Msg3> but was: <Camel Msg4>
刪除testMultipleBodies使測試不會失敗 並更改template.sendBody命令給出 ....Expected: <Camel Msg4> but was: <null>
所以看起來配置中的兩條路線沒有分開?
版本: Apache的駱駝:2.5.0 的Junit:4.11
無我有'expectedBodiesReceivedInAnyOrder'同樣的問題。 (這個問題發生是因爲我試圖添加一個'InAnyOrder'單元測試到一個現有的。)這也不能解釋爲什麼它永遠不會失敗,只有一個testMultipleBodies。 – mkreich