Hi Spencer,

ActorSystems are semi-expensive, starting the dispatcher thread pool etc. 
on startup so this is the rationale for sharing one throughout the test. 
TestKit is built around this and will require a single actor system 
throughout the test. As there are no ties to any specific testing framework 
in the akka testkit there isn't anything shipped with it that hooks up 
before-and-after style hooks - those would be test framework specific. Most 
of the tools that make up testkit is however not dependent on TestKit but 
can be used stand-alone. Starting your actor system is one line of code, 
and shutting it down is one line (TestKit.shutdownActorSystem(system)) so 
hooking it into any test framework should not be much work.
For ScalaTest you can read about using BeforeAndAfter here: 
http://www.scalatest.org/user_guide/sharing_fixtures#beforeAndAfter 
especially the "Calling loan fixture-fixture methods" section where the 
ActorSystem would be what you loan into each test case.

In general if you keep your actors loose coupled and keep them from knowing 
about the absolute paths to other actors tests will be isolated enough even 
if they share actor system that they can even run simultaneously. Some 
times you need isolation though, I wouldn't say that in itself is a smell. 
If no single actor in your entire app can be tested without being isolated 
it may be something to think twice about though.

I hope this helps!
--
Johan Andrén
Akka Team, Lightbend Inc.

On Thursday, April 14, 2016 at 9:06:21 PM UTC+2, Spencer Judge wrote:
>
> I started writing some tests using the TestKit, and it's quite nice - but 
> I quickly realized the ActorSystem persists between tests. This seems a bit 
> odd to me, since it introduces potential coupling between the order of test 
> execution and their results. It doesn't feel like what I would expect the 
> default behavior to be.
>
> Is there a particular reason for this? Is the fact that I want to reset my 
> system between each test a smell? I want to do this in my particular test 
> class because I am testing persistence.
>
> Lastly, is there an easy way to change the behavior?
> I found this old thread:
> https://groups.google.com/forum/embed/#!topic/akka-user/-Cvf9K5P0a0
>
> Which has a solution, albeit a somewhat complicated one. It seems like 
> this would be a very good thing to be able to do simply, without needing to 
> create and destroy a new ActorSystem for every test manually (ex: have a 
> "reset system" method I can call in test teardown). I'm wondering if 
> there's an easier way to do it today.
>
> Thank you!
> Spencer
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to