5

我正在使用 sbt 和 JUnit 为大型 Scala 项目运行测试。我正在分叉多个 JVM进行测试,并定义如何在 JVM 中使用testGrouping in Test.

测试是并行运行的,但它们的输出是交错的,因此很难阅读。我已经设置logBuffered in Test := true了,但这似乎没有做任何事情。

这是我的一个片段settings

parallelExecution in Test := true,
testForkedParallel in Test := false,
concurrentRestrictions in Global := Seq(Tags.limit(Tags.ForkedTestGroup, 8)),

testGrouping in Test := (definedTests in Test, javaOptions in Test) map groupBySuite,
testGrouping in Test := {
  val original: Seq[Tests.Group] = (testGrouping in Test).value

  original.map { group =>
    val forkOptions = ForkOptions(
      bootJars = Nil,
      javaHome = javaHome.value,
      connectInput = connectInput.value,
      outputStrategy = outputStrategy.value,
      runJVMOptions = (javaOptions in Test).value,
      workingDirectory = Some(baseDirectory.value),
      envVars = envVars.value
    )

    group.copy(runPolicy = Tests.SubProcess(forkOptions))
  }
},
logBuffered in Test := true,

我怎样才能让我的测试并行运行,但输出以某种方式被缓冲并按顺序显示,以便它可读?outputStrategy在分叉的 JVM 选项中可能需要提供一些设置吗?

这里有一个类似的问题,但我希望让我的测试保持并行运行。

4

1 回答 1

-1

请参阅http://www.scala-sbt.org/1.x/docs/Parallel-Execution.html

parallelExecution in Test控制测试是否映射到单独的任务。要限制所有项目中同时执行的测试数量,请使用:

concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
于 2017-12-28T05:40:37.643 回答