Hi Derek,
I think one simplification might be to just have a factory method that
produces an AkkaMixin. You could get that by making AkkaMixin a case
class. I might also rename it to ActorSys:
case class ActorSys(name: String) extends TestKit(ActorSystem(name))
with ImplicitSender {
def shutdown(): Unit = system.shutdown()
}
Then your tests would look like:
"TestSpec" should {
"do something correct" in ActorSys("Test1") {
// test stuff here
}
}
(I think. I haven't tried it.) One thing that bugs me about that is
that you have to name your tests twice. One way around that is to come
up with an automated name for the actor system. I'm not sure how much
harder that would make it to figure out errors. If it doesn't really
affect understandability of errors, you could perhaps do this:
case class ActorSys extends TestKit(ActorSystem(generateNextName()))
with ImplicitSender {
def shutdown(): Unit = system.shutdown()
}
Then your tests would look like:
"TestSpec" should {
"do something correct" in ActorSys {
// test stuff here
}
}
The other idea I had is to pass the actual test name in as the actor
system name. But that's more boilerplatey. It would look like this:
case class ActorSys(name: String) extends TestKit(ActorSystem(name))
with ImplicitSender {
def shutdown(): Unit = system.shutdown()
}
import org.scalatest._
import matchers.MustMatchers
class TestSpec extends fixture.WordSpec with MustMatchers {
// Use a fixture.WordSpec and pass the test name into the test
type FixtureParam = String
override def withFixture(test: OneArgTest) {
// To make it stackable, let withFixture(NoArgTest) invoke the function
// If you don't want to make it stackable, then just say test(
test.name)
withFixture.toNoArgTest(
test.name)
}
"TestSpec" should {
"do something correct" in { testName =>
new ActorSys(testName) {
// test stuff here
}
}
}
As I said, more boilerplatey. The best option might be to just name
each test twice. I'll keep thinking. Let me know if you try some of
these and they work or don't. (I'm not the best compiler.)
Bill
--
Bill Venners
Artima, Inc.
http://www.artima.com