Testing Akka.NET Actor Systems

My new Pluralsight course Akka.NET Testing Fundamentals is now available.

Testing actor system brings a number of additional considerations over and above the concepts of traditional object oriented unit/integration testing.

While some additional testing support is required, for example as provided by Akka.NET’s TestKit, concepts such as “unit” and “integration” do translate to the testing of actors. For example a “unit” test becomes a test of the behaviour of a single actor in isolation and an “integration” test may involve multiple actors being testing together.

Just as with traditional OO testing where object dependencies can be mocked, so to with actor tests. For example, TestKit provides a number of pre-built mock actors that can be used if the actor(s) being tested need to be isolated. The simplest of these pre-built mock actors is the BlackHoleActor that will simply and silently accept any message sent to it and “swallow” the message. The EchoActor is another pre-built mock actor that will echo any message sent to it back into the test actor system instance as well as optionally back to the sending actor. The TestProbe pre-built mock actor is a more generalised mock actor and can be used in a number of useful ways.

To get access to the benefits of the actor testing infrastructure, the test class inherits from the TestKit base class. By doing this we get access to an automatically created actor system instance into which we can instantiate the actor(s) that need testing.

When testing an actor, it can be treated as a black or white box. A black box test would involve sending a message to the actor and examining (and asserting on) response message(s). Utilising TestKit we can also write white box actor tests where we can get access to the “internal” actor state directly and make asserts on this internal state.

If you’re new to the Actor Model or Akka.NET, check out the docs or my introductory Pluralsight course: Building Concurrent Applications with the Actor Model in Akka.NET.

You can start watching with a Pluralsight free trial.


Comments (2) -

  • Rajiv

    12/24/2015 6:00:02 AM | Reply

    Love your pluralsight courses on Akka.net. Any plans on covering akka.persistance library?

  • Alberto Monteiro

    1/18/2016 6:59:28 AM | Reply

    @Jason Roberts, when using Dependecy injection with Props.DI()

    Assuming that I have a actor MyActor with the following constructor
    public MyActor(IInterface someDependency, IActorRef actor1, IActorRef actor2, IActorRef actor3)

    I am getting the actor using this line

       var myActorRef = _actorSystem.ActorOf(_actorSystem.DI().Props<MyActor>());

    I have other actors, like MyActor1, MyActor2, MyActor3. So I want to actor1 parameter should be the ref of MyActor1, and so on.

    How should I pass actor as dependencies to another actors?

Pingbacks and trackbacks (2)+

Add comment