expectMsg类型不匹配,需要Int

时间:2016-12-06 15:42:21

标签: scala akka

我有一个演员的以下测试类:

Form

我收到此错误:

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类的子类型。

1 个答案:

答案 0 :(得分:2)

奇怪,它从另一个范围加载隐式。我建议你这样写(如你之前的问题):

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")
  }
}
相关问题