每个配置的类路径依赖关系不适用于SBT中的test->测试?

时间:2013-10-26 23:11:29

标签: scala sbt

我有一个包含scalania主项目以及exercisesanswers(子)项目的多项目构建。

The scalania project托管在GitHub上。

我正在尝试设置一个SBT项目配置,其中测试类是exercises项目的一部分,而answers项目提供解决方案。

我在SBT的官方文档中阅读Per-configuration classpath dependencies,最后在scalania主项目中进行了以下配置:

lazy val exercises = project

lazy val answers = project.dependsOn(exercises % "test->test")

它似乎不起作用,并且在test执行时我曾经得到:

> project answers
[info] Set current project to scalania-answers (in build file:/Users/jacek/oss/scalania/)
> test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for answers/test:test
[success] Total time: 1 s, completed Oct 27, 2013 1:06:51 AM

直到我将answers/build.sbt更改为以下内容:

scalaSource in Test := (scalaSource in LocalProject("exercises") in Test).value

现在工作正常。

> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/oss/scalania/project
[info] Set current project to scalania-answers (in build file:/Users/jacek/oss/scalania/)
> project answers
[info] Set current project to scalania-answers (in build file:/Users/jacek/oss/scalania/)
> testOnly *s99.P01*
[info] Formatting 19 Scala sources {file:/Users/jacek/oss/scalania/}answers(test) ...
[info] Compiling 19 Scala sources to /Users/jacek/oss/scalania/answers/target/scala-2.10/test-classes...
[info] P01Spec
[info]
[info] P01 solution should
[info] + Find the last element of a list
[info]
[info]
[info] Total for specification P01Spec
[info] Finished in 151 ms
[info] 1 example, 0 failure, 0 error
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 74 s, completed Oct 27, 2013 1:09:07 AM

仅使用project.dependsOn(exercises % "test->test")有什么问题?我在构建配置中遗漏了什么吗?

1 个答案:

答案 0 :(得分:2)

声明对另一个项目中的测试的依赖只会使类路径可用。默认情况下不会运行测试,否则测试会在重用代码的常见情况下多次运行。

要在另一个项目中运行测试,请将发现的测试从其他项目添加到当前项目的测试中:

definedTests in Test := 
   (definedTests in Test).value ++
   (definedTests in exercises in Test).value