gpt4 book ai didi

java - Akka FSM : How to write test case to verify state change?

转载 作者:行者123 更新时间:2023-12-02 00:24:23 24 4
gpt4 key购买 nike

我正在使用 Akka FSM。我已经使用 AbstractFSMWithStash 实现了状态更改。但我不确定如何编写单元测试用例来验证参与者是否更改了其状态。 Akka 是否提供任何方法来访问 Actor 的状态以进行单元测试?

我在 https://doc.akka.io/docs/akka/current/fsm.html 的文档页面上找不到太多内容。 .

最佳答案

使用 scala,我们可以使用 TestFSMRef 创建我们想要测试的 FSM actor,然后使用 stateName。示例:

lazy val saleSystemProxy = TestFSMRef(new SaleSystemProxy, "sales-system-fsm")

"Sale System Proxy" should "start in WAITING state" in {
saleSystemProxy.stateName shouldBe ActorState.WAITING
}

it should "stay WAITING if any event passed before configuration" in {
saleSystemProxy ! contract
saleSystemProxy.stateName shouldBe ActorState.WAITING
}

关于java - Akka FSM : How to write test case to verify state change?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58063320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com