I've been looking into code coverage for Play 2.1.x and found that the only
good option is Jacoco.
Its always good to have a fine test coverage in any project. I am working on Play framework & this time i’ve tried to integrate the JaCoCo with my play java project & it’s cool to have it in my project.
There are few easy steps to integrate the JaCoCo in Play project.
1. Add the following lines of code in your plugin.sbt file. You’ve to add the plugin dependency to your project’s plugins.sbt.
6. You’ll find the html file with name index.html which would give
you the full test report. You’ll find this file in this path /target/scala-2.10/jacoco/html
This is how your coverage report would look like :
good option is Jacoco.
Its always good to have a fine test coverage in any project. I am working on Play framework & this time i’ve tried to integrate the JaCoCo with my play java project & it’s cool to have it in my project.
There are few easy steps to integrate the JaCoCo in Play project.
1. Add the following lines of code in your plugin.sbt file. You’ve to add the plugin dependency to your project’s plugins.sbt.
libraryDependencies ++= Seq(
"org.jacoco" % "org.jacoco.core" % "0.5.9.201207300726" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
"org.jacoco" % "org.jacoco.report" % "0.5.9.201207300726" artifacts(Artifact("org.jacoco.report", "jar", "jar")))
addSbtPlugin("de.johoop" % "jacoco4sbt" % "1.2.4")
2. Have this import in your Build.scala file.importde.johoop.jacoco4sbt.JacocoPlugin._
3. Add the following line in your Build.scala file.lazyvaljacoco_settings=Defaults.defaultSettings ++ Seq(jacoco.settings:_*)
4. Add these settings in to your Play project in Build.scala file asvalmain=PlayProject(appName, appVersion, appDependencies,settings=jacoco_settings).settings(parallelExecution in jacoco.Config:=false,jacoco.excludes in jacoco.Config := Seq("views.*", "controllers.Reverse*", "controllers.javascript.*", "controllers.ref.*", "Routes*")
)
5. That’s it. Lets run the JaCoCo with command jacoco:cover This is how your coverage report would look like :


Comments
Post a Comment