[英]Type mismatch for expectMsg, required Int
我為演員准備了以下測試課程:
class SomeActorSpec extends TestKit(ActorSystem("testSystem"))
with ImplicitSender
with WordSpecLike with MustMatchers {
it should "check the id of a submitted job" {
val tester = TestProbe()
val someActorRef = system.actorOf(Props(classOf[SomeActor]))
tester.send(someActorRef, SomeMessage(UUID.randomUUID))
tester.expectMsg(SomeReply("Not running"))
}
}
我收到此錯誤:
type mismatch;
[error] found : your.package.SomeReply
[error] required: Int
[error] tester.expectMsg(SomeReply("Not running"))
為什么期望expectMsg
需要一個Int
? 我查看了使用expectMsg
不同示例,它能夠接收Message
類的子類型。
奇怪,它從另一個范圍隱式加載。 我建議您這樣寫(如您先前的問題):
import java.util.UUID
import akka.actor.{Actor, ActorSystem, Props}
import akka.testkit.{TestKit, TestProbe}
import org.scalatest.FlatSpec
class SomeActorSpec extends FlatSpec {
it should "check the id of a submitted job" in new TestScope {
val tester = TestProbe()
tester.send(someActorRef, SomeMessage(UUID.randomUUID))
tester.expectMsg(SomeReply("Not running"))
}
abstract class TestScope extends TestKit(ActorSystem("testSystem")) {
val someActorRef = system.actorOf(Props(classOf[SomeActor]))
}
}
case class SomeMessage(v: UUID)
case class SomeReply(msg: String)
class SomeActor() extends Actor {
def receive = {
case msg => sender() ! SomeReply("Not running")
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.