我正在开发一个 Spring webflow,尝试使用 TDD,所以我扩展了 AbstractXmlFlowExecutionTests。我看不到一个明显的方法来断言我认为会是一件简单的事情: View 状态具有给定名称的关联 View 。例如,给定此流程(摘录):
<?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
具有 View barView
?
最佳答案
你可以使用这个:
assertResponseWrittenEquals("barView", context);
context
是您的 MockExternalContext
。
无论如何,这就是我总是测试它的方式。
关于java - 在 Spring Webflow 单元测试中,如何断言 View 状态具有给定名称的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/798375/