Spring Web Flow - 如何使用对话范围中已有的值设置单元测试?
我正在开发一个使用 Spring Web Flow 2.0 的项目。
我正在尝试对从决策状态开始的流程进行单元测试。 决策状态检查 conversationScope
上的对象的值。 我不知道如何将值插入到单元测试的 conversationScope
中。
我已经尝试过了:
getConversationScope().put("someName", value);
MockExternalContext context = new MockExternalContext();
startFlow(context);
但是,当我调用 startFlow(context)
时,该值似乎被清除了。
我也尝试过:
MockExternalContext context = new MockExternalContext();
setCurrentState("someDecisionState");
resumeFlow(context)
但是测试失败并出现错误,告诉我无法从决策状态恢复,只能从视图状态恢复。
有谁知道如何在 conversationScope
上插入模拟值以便我可以测试这些案例?
I am working on a project using Spring Web Flow 2.0.
I am trying to unit test a flow that begins with a decision state. The decision state checks the value of an object that is on the conversationScope
. I cannot figure out how to insert a value into the conversationScope
for the unit test.
I have tried:
getConversationScope().put("someName", value);
MockExternalContext context = new MockExternalContext();
startFlow(context);
However, it seems that when I call startFlow(context)
the value is cleared.
I also tried:
MockExternalContext context = new MockExternalContext();
setCurrentState("someDecisionState");
resumeFlow(context)
But the test fails with an error telling me that I cannot resume from a decision state, only from a view state.
Does anyone know how I can insert mock values on the conversationScope
so that I may test these cases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不明显,但我想到了这一点:
我必须深入研究底层
AbstractXmlFlowExecutionTests.startFlow()
以了解它是如何实例化FlowExecution
的,然后复制并粘贴其中一些进入单元测试。这是测试网络流程。
It's not obvious, but I came up with this:
I had to dig into the underlying
AbstractXmlFlowExecutionTests.startFlow()
to see how it was instantiating theFlowExecution
, and copy and paste some of that into the unit test.Here's the test web flow.