我正在从 sbt 11 升级到 sbt 12.2,我们目前有以下项目结构:
src
main
scala/...
test
shared
scala/...
unit
scala/...
integration
scala/...
functional
scala/...
当我升级到 sbt 12 时,测试不再运行,我们得到:No tests to run for unit:test
. 查看 sbt 12 文档,为了使其开箱即用,我们需要为测试源重新构建文件夹和包结构。但是,我想在不得不重组之前先检查是否还有其他事情可以做。
我们的测试配置如下(仅显示单元测试配置,其他测试类型具有相同的配置):
lazy val project = Project(ID, BASE, settings = platformSettings)
.configs(Shared)
.configs(UnitTests)
lazy val Shared = config("shared").extend(Runtime)
lazy val sharedSettings = configure(Shared, "shared")
lazy val UnitTests = config("unit") extend(Shared)
lazy val unitTestSettings = configure(UnitTests, "unit")
private def configure(configuration: Configuration, testType: String) = {
inConfig(configuration)(Defaults.testSettings) ++ inConfig(configuration)(settingsFor(testType))
}
private def settingsFor(testType: String): Seq[Setting[_]] = Seq (
sourceDirectory <<= baseDirectory(_ / "src" / "test" / testType),
testListeners <<= (target in Compile).map({ (target) => Seq(new JUnitXmlTestsListener(target.getAbsolutePath()))}),
parallelExecution := false
)