[英]How can I get the build output directory inside tests run by sbt?
我需要为一些测试创建目录和文件。 我的项目使用 sbt 作为构建工具,通常的做法是使用File.createTempFile
或类似的 API,但我讨厌这种做法。 我希望我的测试创建的所有文件都驻留在 output 目录 ( <module>/target/
) 内的某个位置,以便在我运行clean
时将它们删除,但如果我需要它们来找出测试失败,则保留其他文件.
测试框架无关紧要:如果您的解决方案需要一个特定的框架,我会很乐意采用它或弄清楚它是如何做到这一点并使用它的。
简而言之,我需要这两个问题之一的答案:
在 ScalaTest 中,尝试传递target
settingKey[File]("Main directory for files generated by the build.")
将map 配置为-Dkey=value
。 例如,在build.sbt
中指定
Test / testOptions += Tests.Argument(s"-DtargetDir=${target.value}")
然后像这样定义测试
import org.scalatest._
class ExampleSpec extends fixture.FlatSpec with fixture.ConfigMapFixture with Matchers {
"The config map" should "contain target directory used by sbt" in { configMap =>
configMap should contain key "targetDir"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.