我将Play Framework 2.0配置为使用SCCT进行覆盖,并且可以使用play scct:cover
运行scct。
但是,我的测试无法读取任何配置文件,因为配置文件不在类路径中。即,我使用类型安全的ConfigFactory来加载配置文件,我收到以下错误:
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'KEY.NAME'
play test
和play run
效果非常好。
有什么办法可以强制Play的Build.scala将conf/
目录添加到类路径中吗?
我的plugins.sbt文件的相关部分如下所示:
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += Classpaths.typesafeResolver
resolvers += "scct-github-repository" at "http://mtkopone.github.com/scct/maven-repo"
addSbtPlugin("reaktor" % "sbt-scct" % "0.2-SNAPSHOT")
addSbtPlugin("play" % "sbt-plugin" % "2.0.4")
我的Build.scala的相关部分如下所示:
lazy val additionalSettings = Defaults.defaultSettings ++ seq(ScctPlugin.instrumentSettings: _*)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA, settings = additionalSettings).settings(
testOptions in Test := Nil,
parallelExecution in test := false
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA, settings = additionalSettings).settings(
testOptions in Test := Nil,
parallelExecution in test := false
)
谢谢!
答案 0 :(得分:2)
这可能不是Play特有的。 scct插件应该包含ScctTest配置中Test配置中的资源,就像它对其他类路径元素一样。您可以通过将conf
目录添加到scct的非托管资源目录列表中来自行完成:
unmanagedResourceDirectories in ScctPlugin.ScctTest <+= baseDirectory( _ / "conf")
答案 1 :(得分:0)
Mark的解决方案是正确的,但是我花了一些时间将他的代码放在正确的位置。对于其他任何挣扎于此的人,代码应如下所示:
val main = play.Project(appName, appVersion, appDependencies, settings = scct_settings).settings(
...
unmanagedResourceDirectories in ScctPlugin.ScctTest <+= baseDirectory ( _ / "conf")
...
)