Hello,
I am interested in running some tests in parallel, like Selenium and
integration tests which take a long time to complete. I would like to do this in forked JVMs - simply running the tests in parallel will not work in my case because of global-state changing stuff like dependency injection.
I think I managed to configure my Build.scala to do
this. I divided my tests into some different groups according to their categories and I run these categories in parallel. But since all these JVMs
write to the console at the same time, I get overlapping test result text, which is hard to read.
Here's an excerpt of what I see:
[info] DummySpec
[info] AnotherDBSpec
[info] DBSpec
[info]
[info]
[info]
[info] DBSpec should
[info] AnotherDBSpec should
[info] DummySpec should
[info] + do stuff
[info] + do stuff
[info] + do stuff
[info] Execution time: 10 seconds, 134 ms
[info]
[info]
[info]
[info]
[info] Total for specification DBSpec
[info]
[info] Total for specification DummySpec
[info]
[info] Total for specification AnotherDBSpec
[info] Finished in 10 seconds, 264 ms
[info] 1 example, 0 failure, 0 error
[info]
[info] Finished in 10 seconds, 264 ms
[info] 1 example, 0 failure, 0 error
[info]
[info] Finished in 10 seconds, 356 ms
[info] 1 example, 0 failure, 0 error
[info]
Is there a way for me to specify custom loggers for each forked JVM? I tried Keys.outputStrategy in Test := Some(LoggedOutput(logger))
and passing it my own logger implementation, but apparently it gets
ignored. I am thinking of writing to different OutputStreams then merging them or creating a logging structure that allows only one thing to be written at a time.
This is what my Build.scala looks like, currently:
object ApplicationBuild extends Build {
 val appName = "SBTTest"
 val appVersion = "1.0-SNAPSHOT"
 def groupByCategory(tests: Seq[TestDefinition]) = tests groupBy {
  case t if t.name contains ".unit." => "unit"
  case t if t.name contains ".functional." => "func" + (t.name.hashCode % 4)
  case t if t.name contains ".integration." => "int" + (t.name.hashCode % 4)
 } map {
  case (category, tests) => new Group(category, tests, SubProcess(Seq.empty[String]))
 } toSeq
 val appDependencies = Seq(
  jdbc,
  anorm
 )
 val main = play.Project(appName, appVersion, appDependencies).settings(
 ).settings(
  parallelExecution in Test := true,
  Keys.fork in Test := true,
  concurrentRestrictions in Global := Seq(Tags.limit(Tags.ForkedTestGroup, 8)),
  testGrouping <<= definedTests in Test map {
   test =>
    groupByCategory(test)
  },
  logBuffered in Test := true
 )
}
I am using Play Framework 2.1.2 with sbt 0.12.4 and specs2 by the way.
Thanks in advance,
Emre