Testing streams


(Justin Peel) #1

Any suggestions on testing custom stream stages? It appears that the test artifacts aren’t being published so I’m unable to use StreamSpec like the tests in akka-stream-tests use. I can’t use AkkaSpec like in akka-testkit either. I could copy the files into my project and keep them in the akka namespace, but that seems like a very poor solution.


(Yawar Amin) #2

Can you connect your custom stage to dummy inputs and outputs to verify that it behaves as expected?


(Konrad `ktoso` Malawski) #3

Not sure what you mean; the testkit is published and documented:

https://doc.akka.io/docs/akka/2.5/stream/stream-testkit.html

AkkaSpec is just a small helper class that starts and shuts down the actorsystem, you don’t need it; you can make one yourself and most likely will.


(Yawar Amin) #4

I was referring to the technique recommended here https://doc.akka.io/docs/akka/2.5/stream/stream-testkit.html#built-in-sources-sinks-and-combinators


(Justin Peel) #5

Yes, I am able to make some tests that seem to work.

However, my concern is that my first thought was to look at the akka-stream-tests repo for examples to follow, but they all use code (StreamSpec and assertAllStagesStopped for instance) that isn’t available from outside of the Akka project. Are these components really not important? If so, then why are they used at all? StreamSpec uses AkkaSpec (also not available outside of the Akka repo). assertAllStagesStopped seems like a good thing to do. It uses the akka namespace which makes it harder to duplicate the effect from outside of the akka repo.


(Johan Andrén) #6

akka.stream.testkit.Utils#assertAllStagesStopped is part of the testkit, so that you can use right away, just add the akka-stream-testkit dependency to your project.

StreamSpec and AkkaSpec are internal test base classes that hook into ScalaTest and mostly contain defaults that are useful for testing internal things in Akka, but if you find anything useful in them it should be fairly easy to copy the things you find useful to your own test-baseclass.


(Justin Peel) #7

Thank you for your response. I’m not sure how I can use assertAllStagesStopped though. It is in the test directory of the project and not included in the published jar. I will hope that all is well for now and that I don’t need that coverage, but maybe assertAllStagesStopped should be moved out of the test directory in the future.


(Johan Andrén) #8

The TestKit is intended only for testing, so you’d have a test scoped dependency on it, meaning it is only available in the tests of your project.

Here’s the section of the docs describing how to add it to a project and some examples of what tools it provides: https://doc.akka.io/docs/akka/current/stream/stream-testkit.html#streams-testkit


(Justin Peel) #9

Yes, I am including the testkit as a test dependency just like in the documentation, but Utils is not available under akka.stream.testkit because the test artifacts aren’t published. Utils is under the test directory, not main so my not-akka-keyspaced project can’t see it.


(Johan Andrén) #10

Ah, you are right. My apologies, I incorrectly remembered that we made it a public tool in 2.5.

There is a ticket tracking making it a public part of the TestKit here: https://github.com/akka/akka/issues/21028