This page is no longer maintained — Please continue to the home page at

How to build testcases for Actors

1 reply
Joined: 2008-08-23,
User offline. Last seen 4 years 7 weeks ago.
I have been using actor in my project. I like the clean cut boundarys between them. However I'd really like to have good test cases before I create actors. I have been using JUnit because it integrates nicely with Eclipse, but that is not really mandatory. What has bugged me it how to create test for these actors. Especially since they are asyncronous. I'll give an example:

I have an Actor that is a central repository for object. I talks to other actors that are observers of this object.

Case 1) Observer register and the something gets created:

   repository ! Register(obs1)
   repository ! Register(obs2) // Need this to make sure repository handles more then one actor
   repository ! Create("Something")

Now here is my problem I have to make obs1 and obs 2 actor that expect a message. Is there a easy way to do that?

Case2) Same start as case 1, but after that I have

repository ! Unregister(obs)
repository ! Create("Another thing")

Now I have to recieve the update message on Obs2 and no message on obs1. How do I expect not receiving anythin. I can use receiveWithin, but then what is the correct way to assert things.

I tried creating a Expect Actor were you say what it expects, but I feel I'm not doing it correctly. Is there any work done in the direction? What would be the best way to test actors? Any good tutorial or articles?

Philippe Monnaie
Joined: 2009-01-14,
User offline. Last seen 42 years 45 weeks ago.
Re: How to build testcases for Actors

First, make sure all your code works as it should without contention
problems. You could test this independently for each actor by using a
second actor that send a message and waits for and checks the reply
before sending the next message.

That was the easy part. As far as I know there is no failsafe way to
test random interleavings and contention. You could start with writing
some standard scenarios for your application. This should detect
blatant bugs (no guarantee for detecting more subtle ones).

For more detecting you could try to stress your system (lots of
requests in a short time) and see if it still functions correctly.

It's not a perfect testing procedure, but it's a start.

There's also the findbugs framework that permits you to test specific
interleavings . However, it's based
on threads so you might have to know the internals of actors to make
it work as expected.

Last, but not least, let a few friends or collegues read your code and
try to find out what it does. If what they think it does, differs from
what you want it to do, you might find another error there.

Hope this helps somewhat,


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland