在sbt中执行多个Scalatests

时间:2015-08-12 17:59:17

标签: scala sbt scalatest

我有多个IntelliJ(Scala)模块,它们有build.sbt文件和scalatest代码。

我还为每个人创建了ScalaTest配置。

enter image description here

我可以从执行sbt test逐个运行测试。 是否可以一次执行所有测试?我可以考虑制作一个Python / Bash脚本,但我想知道是否有一种简单的方法可以做到这一点。

for d in dirs:
    execute("sbt test")

ADDED

根据Alexey Romanov的回答,我在根目录中创建了一个build.sbt,内容如下:

lazy val root = (project in file(".")).aggregate(context, contextProcessor)
lazy val context = project
lazy val contextProcessor = project

然后,我执行set test以运行所有测试。

[info] ContextTest:
[info] - Create context
[info] - Create context 2
[info] Run completed in 195 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[info] Compiling 1 Scala source to /Users/smcho/Desktop/code/ContextSharingSimulation/contextProcessor/target/scala-2.11/test-classes...
[info] DatabaseTest:
[info] - Create test
[info] - Create test2
[info] Run completed in 147 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 5 s, completed Aug 12, 2015 3:03:41 PM

参考 - http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Multi-Project.html

1 个答案:

答案 0 :(得分:2)

; <module1>/test; <module2>/test; <module3>/test

或创建aggregate project

// in build.sbt
lazy val root = (project in file(".")).
  aggregate(<module1>, ...)

现在你可以运行sbt test了。实际上,它应该已经默认存在:

  

如果没有为构建中的根目录定义项目,则sbt会创建一个聚合构建中所有其他项目的默认项目。