Question

I want to write a ScalaTest test suite that uses Akka actors and runs from sbt. When I try to do this:

class Tests extends FunSuite with BeforeAndAfterAll {
  override protected def beforeAll() {
    class Actor1 extends Actor {
      protected def receive = {
        case 1 => println("One")
      }
    }
    val sys = ActorSystem("my")
    val a = sys.actorOf(Props[Actor1], "plain_actor")
    a ! 1
    sys.shutdown()
  }
}

and then sbt test, I get

[ERROR] [01/22/2012 12:49:50.329] [default-dispatcher10] [akka://my/user/plain_actor] error while creating actor

But when I write the same code in a usual main class instead of a FunSuite, and run it by sbt run, all works. What is the difference between these two cases and how do I get Akka actors run correctly in a test suite?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top