2013-10-26 79 views
2

我有一個多項目的scalania主項目以及exercisesanswers(子)項目。每個配置的類路徑依賴不適用於SBT中的test-> test?

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")有什麼問題?我在構建配置中丟失了些什麼?

+0

是,你必須在一個子項目'exercises'測試類的問題,你想運行他們在另一個子項目'答案',只是取決於'演習'? –

+0

是的。這就是我喜歡用SBT中的慣用方式來挑選的問題。如果有這樣的方式,讓我知道@MarkHarrah。 –

回答

2

在另一個項目中聲明對測試的依賴只會使類路徑可用。運行它的測試不會默認發生,因爲否則測試會在僅重用代碼的常見情況下運行多次。

要在另一個項目運行測試,從其他項目中添加的測試發現,那些對當前項目:

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