2011-01-21 52 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