I run my scalatest from sbt, and the output gets mixed up - scalatest prints all the test run, and comments to them, and somewhere in the middle it prints the statistics:
Have the same issue and solved it by saving logs into separate files. Not ideal, but good for CI, especially in case of long-running integration tests. How I did it:
Create a special directory for logs (for example, at the end of build.sbt):
lazy val logDirectory = taskKey[File]("A directory for logs")
logDirectory := {
val r = target.value / "logs"
IO.createDirectory(r)
r
}
[Optionally] Specify a file for a summary information in a project:
testOptions in test += Tests.Argument(
TestFrameworks.ScalaTest, "-fW", (logDirectory.value / "summary.log").toString
)
W disables colors
Create a group for each test. Each group must run a test in a forked JVM with special arguments:
testGrouping in test := testGrouping.value.flatMap { group =>
group.tests.map { suite =>
val fileName = {
// foo.bar.baz.TestSuite -> f.b.b.TestSuite
val parts = suite.name.split('.')
(parts.init.map(_.substring(0, 1)) :+ parts.last).mkString(".")
}
val forkOptions = ForkOptions(
bootJars = Nil,
javaHome = javaHome.value,
connectInput = connectInput.value,
outputStrategy = outputStrategy.value,
runJVMOptions = javaOptions.value ++ Seq(
"-Dour.logging.appender=FILE",
s"-Dour.logging.dir=${logDirectory.value / fileName}"
),
workingDirectory = Some(baseDirectory.value),
envVars = envVars.value
)
group.copy(
name = suite.name,
runPolicy = Tests.SubProcess(forkOptions),
tests = Seq(suite)
)
}
}
Note, we can tell the logback, where we save our logs through our.logging.appender and our.logging.dir
Create a configuration for logging (test/resources/logback-test.xml):
System.out
%date{yyyy-MM-dd HH:mm:ss} %-5level [%thread] %logger{26} - %msg%n
${our.logging.dir}/test.log
false
%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{26} - %msg%n
That's all.