Questions tagged [akka-testkit]

Akka comes with a dedicated module akka-testkit for supporting tests at different levels.

140 questions
16
votes
3 answers

How to test client-side Akka HTTP

I've just started testing out the Akka HTTP Request-Level Client-Side API (Future-Based). One thing I've been struggling to figure out is how to write a unit test for this. Is there a way to mock the response and have the future completed without…
steinybot
  • 5,491
  • 6
  • 37
  • 55
10
votes
1 answer

How do I test an Akka actor that sends a message to another actor?

I'm using ScalaTest with the Akka TestKit to write unit and integration tests for an actor I've coded to simply send a message to another actor without mutating any internal state. Take this for example: class MyActor extends Actor { val…
nmurthy
  • 1,337
  • 1
  • 12
  • 24
9
votes
3 answers

Akka Http Route Test: Request was neither completed nor rejected within 1 second

I am trying to write a test case for my application with akka-http. One of the testcases is given below: import akka.http.scaladsl.model.headers.RawHeader import akka.http.scaladsl.testkit.{ ScalatestRouteTest} import…
Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80
7
votes
1 answer

Akka Actor Test: Automatic reply with a TestProbe

I am trying to get a test probe to reply with an acknowledgement, whenever it receive any message . I wrote the following code in my test but it does not work: val chgtWriter = new TestProbe(system) { def receive: Receive = { …
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
7
votes
2 answers

Akka unit testing strategies without mocks

MAIN IDEA: How can we unit test (or re-factor to facilitate unit testing) Akka actors with fairly complex business logic? I have been using Akka for a project at my company (some very basic stuff is in production) and have been continuously…
jm0
  • 3,294
  • 2
  • 16
  • 18
7
votes
1 answer

How to mock an Akka Actor to Unit Test a class?

I have a Controller class which controls the requests sent to a Akka actor which is injected in to the controller. Controller's code: class Controller(actor: ActorRef) { def control(msg: String): Future[String] = { actor.ask(msg)(Timeout(2…
himanshuIIITian
  • 5,985
  • 6
  • 50
  • 70
5
votes
1 answer

Is it possible for a test message sent to a `TestProbe` to arrive before `TestActor.SetAutoPilot(pilot)`

Akka Testkit AutoPilot documentation examples show that we can send messages to a TestProbe right after invoking setAutoPilot: probe.setAutoPilot(new TestActor.AutoPilot { def run(sender: ActorRef, msg: Any): TestActor.AutoPilot = msg…
5
votes
2 answers

Akka Actors unit testing for dummies

I'm newbie in Akka and Scala and i come from a non-concurrent world. Probably i'm doing a lot of things wrong, i will appreciate feedback even it's not related to the question. I'm doing a simple chat application with Akka and Scala. I started (bc…
SergiGP
  • 669
  • 7
  • 17
5
votes
2 answers

How to respond to an Ask pattern with a failure using Akka TestKit?

I have an Akka Actor which uses the Ask pattern to retrieve a Future from a child actor and acts on both success and failure. I cannot work out how to mock out the child actor and respond with failures. Here's the code: import…
William Carter
  • 1,287
  • 12
  • 19
5
votes
2 answers

Akka: testing monitoring\death watch

In my scenario I have 2 actors: watchee (I use TestProbe) watcher (Watcher wrapped into TestActorRef to expose some internal state I track in my test) Watcher should take some actions when watchee dies. Here is the complete test case I've written…
Eugene Loy
  • 12,224
  • 8
  • 53
  • 79
4
votes
2 answers

Why does adding Thread.sleep make my Akka TestKit unit tests pass?

Java 8 and Akka (Java API) 2.12:2.5.16 here. I have the following message: public class SomeMessage { private int anotherNum; public SomeMessage(int anotherNum) { this.anotherNum = anotherNum; } public int getAnotherNum()…
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
4
votes
1 answer

How to test DistributedPubSub with the TestKit in Akka.net?

I am unit-testing an actor that uses the Cluster tool DistributedPubSub. For the tests I am using the TestKit of Akka.net. Apparently, in the TestKit, the system actor Sys doesn't have the DistributedPubSub tool and it throws a Null pointer…
Belén Morenate
  • 369
  • 3
  • 9
4
votes
2 answers

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…
Rafael Pacheco
  • 472
  • 1
  • 5
  • 15
4
votes
2 answers

How to use Akka-TestKit TestProbe correctly?

I expanded the example from http://doc.akka.io/docs/akka/snapshot/scala/testing.html#Using_Multiple_Probe_Actors. import akka.actor._ import akka.testkit.{TestProbe, TestKit} import org.scalatest.{Suites, BeforeAndAfter, BeforeAndAfterAll,…
hami
  • 443
  • 5
  • 13
4
votes
1 answer

How to ignore single test in testKit

I have a series of tests in the same class all testing the same feature , how can I skip/ignore a single one e.g: class FooTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender with WordSpecLike with Matchers { implicit val…
igx
  • 4,101
  • 11
  • 43
  • 88
1
2 3
9 10