Skip to content

Instantly share code, notes, and snippets.

@jbellenger
Last active December 18, 2015 18:19
Show Gist options
  • Save jbellenger/5824938 to your computer and use it in GitHub Desktop.
Save jbellenger/5824938 to your computer and use it in GitHub Desktop.
The goal here is to create an entire akka ActorSystem for each test case with minimum boilerplate required for each test.
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FunSuite
import akka.actor._
import akka.actor.Actor.emptyBehavior
import akka.testkit.{TestKit, ImplicitSender}
class DummyActor extends Actor {
val receive = emptyBehavior
}
abstract class ActorTestCase extends TestKit(ActorSystem("per-test-actorsystem")) with ImplicitSender
@RunWith(classOf[JUnitRunner])
class DummyTest extends FunSuite {
// can this syntax be simplified to implicitly create an ActorTestCase with a constructor provided here?
test("foo") (
new ActorTestCase {
// system provided by TestKit
val ref = system.actorOf(Props[DummyActor], "mydummy")
// assert and === provided by FunSuite
assert(ref.isTerminated === false)
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment