Search code examples
javatestingakkaactorakka-testkit

How to mock a actor based on ActorSelection?


I have searched a lot about this and yet have no answer.

I have a Actor "A" (user/A) that send message "X" for a other actor "B" (user/B) when receive a message "M". To do this the actor A use ActorSelection I need test that when I send M to A, B will receive "X".

I try do this using TestProbe on "user/B" but have not success.

I also see some similar questions about this but every answer said to use ActorRef insted of ActorSelection. This is not a option for me, I realy need use a ActorSelection.

Someone have some idea ?


Solution

  • Simple answer: instead of hard-coding the selection’s path in A make that configurable. In the test you can then point that to the path of a TestProbe.