在 Spring Webflow 单元测试中,如何断言视图状态具有给定名称的视图?
我正在开发 Spring webflow,尝试使用 TDD,因此我扩展了 AbstractXmlFlowExecutionTests。 我看不到一种明显的方法来断言我认为是一件简单的事情:视图状态具有给定名称的关联视图。 例如,给定此流程(摘录):
<?xml version="1.0" encoding="UTF-8"?>
<flow ...>
...
<view-state id="foo" view="barView">
</view-state>
</flow>
和单元测试
public void testAssertFooStateHasBarView() {
...
assertCurrentStateEquals("foo");
assertTrue( getFlowDefinition().getState("confirmation").isViewState());
// Surely there's an easier way...?
ViewState viewState = (ViewState)getFlowDefinition().getState("foo");
View view = viewState.getViewFactory().getView(new MockRequestContext());
// yuck!
assertTrue(view.toString().contains("barView"));
}
是否有更简单的方法来断言状态 foo
具有视图 barView
?
I'm developing a Spring webflow, trying to use TDD so I've extended AbstractXmlFlowExecutionTests. I can't see an obvious way to assert what I would have thought would be a simple thing: that a view state has an associated view of a given name. For example, given this flow (excerpt):
<?xml version="1.0" encoding="UTF-8"?>
<flow ...>
...
<view-state id="foo" view="barView">
</view-state>
</flow>
and unit test
public void testAssertFooStateHasBarView() {
...
assertCurrentStateEquals("foo");
assertTrue( getFlowDefinition().getState("confirmation").isViewState());
// Surely there's an easier way...?
ViewState viewState = (ViewState)getFlowDefinition().getState("foo");
View view = viewState.getViewFactory().getView(new MockRequestContext());
// yuck!
assertTrue(view.toString().contains("barView"));
}
Is there a simpler way to assert that state foo
has view barView
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用以下内容:
其中
context
是您的MockExternalContext
。无论如何,这就是我总是测试的方式。
You can use this:
Where
context
is yourMockExternalContext
.This is how I always test this anyway.
如果您实际上是在发送事件信号,则可以通过此方法获取 ViewSelection 并检查名称:
If you are actually signaling events, you can get the ViewSelection and check the name via this method:
我无法谈论您的其余测试,或如何使用 Webflow,但您为什么使用
contains()
来测试相等性? 我确信您不希望“barViewBlah”视图与您的测试相匹配,是吗?I can't speak to the rest of your tests, or how to use Webflow, but why are you using
contains()
to test for equality? I'm sure you don't want a view of "barViewBlah" to match your test, do you?