Configuration files not in Play Framework 2.0 classpath when calculating code coverage using SCCT

1.2k views Asked by At

I configured the Play Framework 2.0 to use SCCT for coverage, and can run scct using play scct:cover.

However, my tests are unable to read any configuration files, because the configuration files are not in the classpath. To wit, I am using the typesafe ConfigFactory to load the configuration files, and I receive the following error: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'KEY.NAME'

play test and play run work perfectly well.

Is there some way I can force Play's Build.scala to add the conf/ directory to the classpath?

The relevant portion of my plugins.sbt file looks like this: 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")

The relevant portion of my Build.scala looks like this: 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
)

Thanks!

2

There are 2 answers

2
Mark Harrah On BEST ANSWER

This is probably not specific to Play. The scct plugin should probably include the resources in the Test configuration in the ScctTest configuration like it does for other classpath elements. You can do it yourself explicitly by adding the conf directory to the list of unmanaged resource directories for scct:

unmanagedResourceDirectories in ScctPlugin.ScctTest <+= baseDirectory( _ / "conf")
0
keslert On

Mark's solution is correct, however it took me a while to put his code in the right place. For anyone else struggling with this, the code should look as follows:

val main = play.Project(appName, appVersion, appDependencies, settings = scct_settings).settings(
    ...
    unmanagedResourceDirectories in ScctPlugin.ScctTest <+= baseDirectory ( _ / "conf")
    ...
)