簡體   English   中英

類型為ExpectMsg不匹配,必需為Int

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM