如何 运行 在用 Java 编写的多模块播放项目中进行单元测试

How to run unit test in a multi-module play project written in Java

所以我有一个播放项目的项目结构如下,写在Java:

conf\
modules\
    first\
        app\
        test\
    second\
        app\
        test\ 
build.sbt

在我的 build.sbt 我有以下内容


lazy val first= project.in(file("modules/first"))
  .enablePlugins(PlayMinimalJava)

lazy val first= project.in(file("modules/second"))
  .enablePlugins(PlayMinimalJava)

lazy val whole = project.in(file("."))
  .enablePlugins(PlayMinimalJava)
  .dependsOn(first, second)

现在,我想 运行 位于每个子项目中的 JUnit 测试。当我将它们放在 test/ 的根目录时,如果我这样做 sbt test,它们会 运行。但是如果将它们移动到子项目测试目录中 - 在 modules/first/test/modules/second/test/ - 它们不会 运行.

我的测试可以缺少什么?运行?

您需要使用聚合。这里引自 sbt docs

Aggregation means that running a task on the aggregate project will also run it on the aggregated projects.

试试这个

lazy val whole = project.in(file("."))
  .aggregate(first, second)
  .enablePlugins(PlayMinimalJava)
  .dependsOn(first, second)