我刚刚用最新的Play2.3.1和jacoco4sbt 2.1.5对其进行了第一次测试,结果毫无问题。老实说,我自己都很惊讶,事情进展得如此顺利。
您不需要以下内容
项目/插件.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"))
)
为了测试它,我首先使用Typesafe Activator创建了Play应用程序
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
进入shell并执行
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
到
建筑.sbt
在顶级目录中。我还补充了
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.5")
到
项目/插件.sbt
.
未进行其他更改。
我
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