Spring StateMachine使用StateMachineTestPlan来测试withChoice转换.<



如果我有一个statemmachine设置如下:

transitionConfigurer
.withExternal()
.source(FIRST)
.event(EVENT_1)
.target(SECOND)
.and()
.withChoice()
.source(SECOND)
.first(THIRD, new Guard(someService))
.last(FIRST)
.and()
.withExternal()
.source(THIRD)
.event(EVENT_2)
.target(FIRST);

如何使用StateMachineTestPlan来测试withChoice。

我有一个StateMachineTestPlan设置如下,这创建了一个初始状态为SECOND的状态机,然后我希望能够测试选择。然而,当我在测试计划中执行.step()时,什么也没有发生:

createStateMachineAndSetInitialState(SECOND, workflowCreator);
StateMachineTestPlan<State, Event> plan = StateMachineTestPlanBuilder.<State, Event> builder()
.defaultAwaitTime(1)
.stateMachine(machine)
.step()
.expectState(THIRD)
.and()
.build();
plan.test();

首先,你能分享你对下面方法的自定义重写吗?

你需要确保你已经配置了这样的选择状态:

@Override
public void configure(final StateMachineStateConfigurer<States, Events> states)
throws Exception {
states
.withStates()
.initial(States.FIRST)
.choice(States.SECOND) 
.end(States.LAST)
.states(States.enumSet);
}

似乎你达到了状态(SECOND),但没有进入CHOICE伪状态。你的测试停在哪个州?

最新更新