2011-01-21 62 views
4

我想測試編譯動作把SRC /測試的內容/資源投入到目標/ scala_2.8.1 /測試類。如何更改成SBT把測試資源的目錄?

原因是我正在運行帶有IntelliJ IDEA的SBT,它在運行測試時將test-classes目錄放在classpath中。

我的logback-test.xml文件(用於logback日誌框架的配置)位於src/test/resources中,並且在測試期間未找到它。

回答

4

這並不直接回答你的問題,而是顯示了,我使用的替代品。

我添加了兩項新任務:preparetest-prepare

lazy val prepare = task{ 
    None 
} dependsOn (compile, copyResources) describedAs ("Compiles main, copies main resources. Use for the before-action in the idea-sbt-plugin") 

lazy val testPrepare = task{ 
    None 
} dependsOn (testCompile, copyResources, copyTestResources) describedAs ("Compiles main and test, copies all resources. Use for the before-action in the idea-sbt-plugin") 

然後我配置'before run'SBT動作到這些。這需要idea-sbt-plugin

alt text

我使用sbt-idea SBT處理器配置的IntelliJ模塊設置。這包括target/scala_2.8.1/[test-]resources作爲依賴項。

alt text

+0

理念構建過程拷貝資源到`classes`和`測試classes`目錄,因爲那時你結束了兩套資源,這是煩人。 – David 2011-04-22 01:53:19

2

儘管可能有更好的方法來做,但只要沒有別的選項覆蓋testCompile,就可以工作。只需將以下內容添加到您的項目定義中。

override lazy val testCompile = testCompileAction dependsOn task { 
    import sbt.Process._ 
    "cp -R src/test/resources/* target/scala_2.8.1/test-classes" ! log 
    None 
} 
1
override lazy val testCompile = testCompileAction dependsOn copyTestResources 
override def testResourcesOutputPath = testCompilePath 
+0

與複印測試的資源投入到testCompilePath唯一的問題是,編譯器檢測到** **每次運行修改,速度變慢增色不少。 – David 2011-04-22 01:35:00