class MyWebSocketActorTest extends Specification with Mockito {
val system = ActorSystem("MockActorSystem")
val mockMap : Map[ActorRef , String] = Map()
val mockCache = mock[CacheApi]
val actor1 = system.actorOf(Props[ChatActor],"actor1")
val actor2 = system.actorOf(Props[ChatActor],"actor2")
"MyWebSocketActor receive function" should {
"have username key" in {
val testActor = system.actorOf(Props(new MyWebSocketActor(actor1 , actor2, mockCache , mockMap)))
val testMsg1 = Json.parse("""{"message":"Testing Message 2","conn_status":2,"pub_key":"empty","target":"all"}""")
testActor ! testMsg1
}
}
}
我正在使用Akka 2.4.7在Play 2.5.3和Scala中工作。我有一个看起来像此类的课程
MyWebSocketActor(out:ActorRef,postActor:ActorRef,cache:CacheApi,postActorToUsernameMap:Map[ActorRef,String]) extends Actor
我想创建此类的actor并调用其receive函数。我也尝试过在此链接Akka Java : create an actor with constructor taking parameters中建议。但是每次它给我错误:
构造函数MyWebSocketActor的参数过多:()test.MyWebSocketActor
我在这里做错了什么?
最佳答案
您的演员MyWebSocketActor
正在被您的测试服遮盖。将测试类更改为MyWebSocketActor
以外的其他名称,例如MyWebSocketActorTest