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.
Can you connect your custom stage to dummy inputs and outputs to verify that it behaves as expected?
Not sure what you mean; the testkit is published and documented:
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.
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
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.
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.
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.
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.
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
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.
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