0
votes

I am using TestKit to test the Akka Actors. I have a class Demo which has method getActorRef, which takes input as string and returns an ActorRef.

class Demo @Inject()(a: A. b: B, context: ActorContext) {
  def getActorRef(id: String): ActorRef
}

I have mocked A,B while creating object of Demo.Now i am facing issue how to mock context.

What i did to mock it ? val context = mock[ActorContext]

But it didn't work.

1
Does it have to be mocked? why not use the akka testkit to provide an ActorContext? similar to stackoverflow.com/questions/36945414/…Ramón J Romero y Vigil

1 Answers

0
votes

It's not clear exactly what you're trying to do, or what errors you're encountering. I'm guessing you're using the ActorContext to get an ActorRef inside getActorRef. If so, have you tried using Mockito to create a mock ActorContext, passing that into Demo when you construct it in the test, then stubbing out the ActorContext method called by getActorRef so that it returns the value you want (i.e., a ref to a test probe, or some such thing)?

I'd expect that to work, assuming that's what you're trying to do.