我剛剛用最新的Play 2.3.1和jacoco4sbt 2.1.5進行了第一次測試,它沒有任何問題。老實說,我很驚訝自己有多順利。
您不需要按照項目/ 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"))
)
爲了測試它,我首先創建使用play-scala
模板使用類型安全的激活播放應用程序。
➜ 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
我然後跑activator
進入外殼並執行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
繼the Wiki on jacoco4sbt plugin site on GitHub,我再在頂層目錄添加到jacoco.settings
build.sbt。我還添加了addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")
到project/plugins.sbt。
沒有其他改變。
I reload
編輯激活器外殼以加載更改。
[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/)
當我運行jacoco:cover
插件執行並顯示結果。
[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
這裏是項目的狀態。
[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
您可以將'sbt --version'和'sbt about'的輸出添加到問題中嗎? –