Testing stream-based code might look complex because of the interconnectedness of all of the parts of the system. But more often than not testing streams boils down to unit-testing processing stages in isolation and relying on the Akka Streams that data flow between this stages will happen as expected.
Frequently, no special testing library is needed. Let's demonstrate this by testing our source:
"manager source" should {
"emit shopping lists as needed" in {
val future: Future[Seq[ShoppingList]] = Manager.manager.take(100).runWith(Sink.seq)
val result: Seq[ShoppingList] = Await.result(future, 1.seconds)
assert(result.size == 100)
}
}
In order to run this test snippet we need an implicit materializer to be in scope:
implicit val as: ActorSystem = ActorSystem("test")
implicit val mat: Materializer = ActorMaterializer()
The general...