2

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

scalania 项目托管在 GitHub 上。

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

我在 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")?我在构建配置中遗漏了什么吗?

4

1 回答 1

2

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

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

definedTests in Test := 
   (definedTests in Test).value ++
   (definedTests in exercises in Test).value
于 2013-11-04T15:10:02.827 回答