Reputation: 41
I can run my tests using sbt test
. When I run the tests using sbt jacoco:cover
or sbt jacoco:test
and sbt jacoco:report
however I get 0 tests, 0 errors, 0 failures
. Jacoco sees my test files but not the tests
project/Build.scala
import sbt._
import Keys._
import play.Project._
import de.johoop.jacoco4sbt._
import JacocoPlugin._
object ApplicationBuild extends Build {
val appName = "api"
val appVersion = "0.1-SNAPSHOT"
lazy val s = playJavaSettings ++ Seq(jacoco.settings:_*)
val appDependencies = Seq(
"com.novocode" % "junit-interface" % "0.8" % "test"
)
val main = play.Project(appName, appVersion, appDependencies, settings = s).settings(
**various resolvers**
).settings(
jacoco.settings : _*
).settings(
testOptions in jacoco.Config += Tests.Argument("junitxml")
).settings(
testOptions in jacoco.Config += Tests.Setup( () => System.setProperty("config.file", "conf/application.conf") )
).settings(
parallelExecution in jacoco.Config := false
)
}
project/plugins.sbt
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")
// Use jacoco on sbt builds
libraryDependencies ++= Seq(
"org.jacoco" % "org.jacoco.core" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
"org.jacoco" % "org.jacoco.report" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.report", "jar", "jar"))
)
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")
My tests are under the tests directory
I am using:
Most of the answers I found online for people running into the same issue was a matter of parallelExecution
not being set to false
. When I check sbt jacoco:parallelExecution
in the api
directory it is set to false
. But when I run sbt jacoco:parallelExecution
in the project
or test
directory it is set to true
.
Upvotes: 2
Views: 1601
Reputation: 41
It started working once I added
.settings(
Keys.fork in jacoco.Config := true
)
to my Build.scala file. I wish I could explain more on how this worked but it is still a little fuzzy.
Thanks everyone for the answers. It works great locally now, but still getting 0 tests run in Jenkins.
Upvotes: 1
Reputation: 13749
You have to remove following line.
testOptions in jacoco.Config += Tests.Argument("junitxml")
This is not supported opiton. For the list of supported options check the documentation
Upvotes: 0
Reputation: 74679
I've just tested it for the first time with the latest Play 2.3.1 and jacoco4sbt 2.1.5, and it worked with no issues. Honestly, I was very much surprised myself how smooth it went.
You don't need the following in project/plugins.sbt:
// Use jacoco on sbt builds
libraryDependencies ++= Seq(
"org.jacoco" % "org.jacoco.core" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
"org.jacoco" % "org.jacoco.report" % "0.5.7.201204190339" artifacts(Artifact("org.jacoco.report", "jar", "jar"))
)
To test it, I first created the Play application using Typesafe Activator using the play-scala
template.
➜ sandbox activator new play-jacoco play-scala
Fetching the latest list of templates...
OK, application "play-jacoco" is being created using the "play-scala" template.
To run "play-jacoco" from the command line, "cd play-jacoco" then:
/Users/jacek/sandbox/play-jacoco/activator run
To run the test for "play-jacoco" from the command line, "cd play-jacoco" then:
/Users/jacek/sandbox/play-jacoco/activator test
To run the Activator UI for "play-jacoco" from the command line, "cd play-jacoco" then:
/Users/jacek/sandbox/play-jacoco/activator ui
➜ sandbox cd play-jacoco
I then ran activator
to enter the shell and executed test
.
➜ play-jacoco activator
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/play-jacoco/project
[info] Updating {file:/Users/jacek/sandbox/play-jacoco/project/}play-jacoco-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to play-jacoco (in build file:/Users/jacek/sandbox/play-jacoco/)
[play-jacoco] $ test
[info] Updating {file:/Users/jacek/sandbox/play-jacoco/}root...
[info] Resolving jline#jline;2.11 ...
[info] Done updating.
[info] Compiling 5 Scala sources and 1 Java source to /Users/jacek/sandbox/play-jacoco/target/scala-2.11/classes...
[info] Compiling 2 Scala sources to /Users/jacek/sandbox/play-jacoco/target/scala-2.11/test-classes...
[info] IntegrationSpec
[info]
[info] Application should
[info] + work from within a browser
[info]
[info] Total for specification IntegrationSpec
[info] Finished in 2 seconds, 615 ms
[info] 1 example, 0 failure, 0 error
[info] ApplicationSpec
[info]
[info] Application should
[info] + send 404 on a bad request
[info] + render the index page
[info]
[info] Total for specification ApplicationSpec
[info] Finished in 130 ms
[info] 2 examples, 0 failure, 0 error
[info] Passed: Total 3, Failed 0, Errors 0, Passed 3
[success] Total time: 17 s, completed Jul 11, 2014 7:57:23 PM
Following the Wiki on jacoco4sbt plugin site on GitHub, I then added jacoco.settings
to build.sbt in the top-level directory. I also added addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")
to project/plugins.sbt.
No other changes were made.
I reload
ed the activator shell to load the changes.
[play-jacoco] $ reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/play-jacoco/project
[info] Updating {file:/Users/jacek/sandbox/play-jacoco/project/}play-jacoco-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to play-jacoco (in build file:/Users/jacek/sandbox/play-jacoco/)
When I ran jacoco:cover
the plugin executed and displayed the results.
[play-jacoco] $ jacoco:cover
[info] Updating {file:/Users/jacek/sandbox/play-jacoco/}root...
[info] Resolving org.jacoco#org.jacoco.agent;0.7.0.201403182114 ...
[info] Done updating.
[info] ApplicationSpec
[info]
[info] Application should
[info] + send 404 on a bad request
[info] + render the index page
[info]
[info] Total for specification ApplicationSpec
[info] Finished in 22 ms
[info] 2 examples, 0 failure, 0 error
[info] IntegrationSpec
[info]
[info] Application should
[info] + work from within a browser
[info]
[info] Total for specification IntegrationSpec
[info] Finished in 22 ms
[info] 1 example, 0 failure, 0 error
[info] Passed: Total 3, Failed 0, Errors 0, Passed 3
[info]
[info] ------- Jacoco Coverage Report --------
[info]
[info] Lines: 57.5% (>= required 0.0%) covered, 34 of 80 missed, OK
[info] Instructions: 71.94% (>= required 0.0%) covered, 523 of 1864 missed, OK
[info] Branches: 27.78% (>= required 0.0%) covered, 26 of 36 missed, OK
[info] Methods: 81.94% (>= required 0.0%) covered, 41 of 227 missed, OK
[info] Complexity: 76.73% (>= required 0.0%) covered, 57 of 245 missed, OK
[info] Class: 57.14% (>= required 0.0%) covered, 12 of 28 missed, OK
[info] Check /Users/jacek/sandbox/play-jacoco/target/scala-2.11/jacoco for detail report
[info]
[success] Total time: 4 s, completed Jul 11, 2014 8:01:00 PM
Here's the status of the project.
[play-jacoco] $ about
[info] This is sbt 0.13.5
[info] The current project is {file:/Users/jacek/sandbox/play-jacoco/}root 1.0-SNAPSHOT
[info] The current project is built against Scala 2.11.1
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, play.Play, play.PlayJava, play.PlayScala, play.twirl.sbt.SbtTwirl, com.typesafe.sbt.jse.SbtJsEngine, com.typesafe.sbt.jse.SbtJsTask, com.typesafe.sbt.web.SbtWeb, com.typesafe.sbt.webdriver.SbtWebDriver, com.typesafe.sbt.coffeescript.SbtCoffeeScript, com.typesafe.sbt.less.SbtLess, com.typesafe.sbt.jshint.SbtJSHint, com.typesafe.sbt.rjs.SbtRjs, com.typesafe.sbt.digest.SbtDigest, com.typesafe.sbt.mocha.SbtMocha, net.virtualvoid.sbt.graph.Plugin, com.timushev.sbt.updates.UpdatesPlugin, com.typesafe.sbteclipse.plugin.EclipsePlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.SbtNativePackager, de.johoop.jacoco4sbt.JacocoPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.4
Upvotes: 0