SBT不编译位于自定义测试源文件夹中的测试

时间:2018-12-13 19:19:28

标签: scala sbt

我的项目中有3个测试源文件夹。我在build.sbt(SBT版本:1.2.1)中添加了以下密钥:

sourceDirectories in Test := baseDirectory { base =>
  Seq(
    base / "src/test/common/scala",
    base / "src/test/unit/scala",
    base / "src/test/functional/scala"
  )
}.value

SBT正确识别了文件夹:

sbt test:sourceDirectories
...
[info] Set current project to service (in build file:/myprojectfolder/)
[info] * /myprojectfolder/src/test/common/scala
[info] * /myprojectfolder/src/test/unit/scala
[info] * /myprojectfolder/src/test/functional/scala

但是test:compiletarget/scala-2.11/test-classes中不产生任何测试类,结果test任务没有运行任何测试。

我正在使用ScalaTest 3.0.5,尽管这似乎无关紧要。

有什么想法为什么SBT在编译过程中会忽略测试Scala源?

1 个答案:

答案 0 :(得分:0)

manuzhang感谢您提供有用的评论。确实,以下更改可以解决问题:

代替

sourceDirectories in Test := baseDirectory { base =>
  Seq(
    base / "src/test/common/scala",
    base / "src/test/unit/scala",
    base / "src/test/functional/scala"
  )
}.value

我用过

unmanagedSourceDirectories in Test := baseDirectory { base =>
  Seq(
    base / "src/test/common/scala",
    base / "src/test/unit/scala",
    base / "src/test/functional/scala"
  )
}.value