2016-12-06 5 views
1

私はAkkaのコンポーネントの次のテストを持っている:見つかりません:値expectMsg

import somePackage.SomeActor 
import akka.actor.{ActorSystem, Props} 
import org.scalatest.{FlatSpec, Matchers} 

class SomeActorSpec extends FlatSpec with Matchers { 

    val system = ActorSystem() 
    val someActorRef = system.actorOf(Props(classOf[SomeActor])) 


    it should "check the id" in { 
    someActorRef ! CheckIfJobIsRunning(UUID.randomUUID) 
    expectMsg(SomeOtherMessage(List())) 
    } 

} 

私はエラーを取得する:

1.How缶:

not found: value expectMsg 
[error]  expectMsg(SomeOtherMessage(List())) 

は、私は2つの質問があります私はexpectMsgを使用していますか?

2.テストクラスで受信する必要があるSomeOtherMessageを定義しますか?

答えて

2

TestKitスコープを使用してください。例は次のようになります:

class SomeActorSpec extends FlatSpec with Matchers { 
    it should "check the id" in new Scope { 
    someActorRef ! CheckIfJobIsRunning(UUID.randomUUID) 
    expectMsg(SomeOtherMessage(List())) 
    } 

    abstract class Scope extends TestKit(ActorSystem()) { 
    val someActorRef = system.actorOf(Props(classOf[SomeActor])) 
    } 
} 

詳細はdocsです。ご質問について:それはCheckIfJobIsRunning

  • があなたの俳優に関連するすべてのメッセージが含まれているいくつかのプロトコルのようなファイルにCheckIfJobIsRunningSomeOtherMessageなどを定義して受信したときにその俳優をテストするための

    1. 使用expectMsgは、いくつかの他のアクターにSomeOtherMessageを送信します。私は個人的にこれらのメッセージをすべて指定するために俳優の仲間のオブジェクトを使用します。
  • 関連する問題