Integrating JaCoCo in your Play Scala project

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 scala project & it’s cool to have it in my project.

I am going to elaborate a few easy steps to integrate the JaCoCo in Play Scala 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" % "" artifacts(Artifact("org.jacoco.core", "jar", "jar")),
 	"org.jacoco" % "" % "" artifacts(Artifact("", "jar", "jar")))

 addSbtPlugin("de.johoop" % "jacoco4sbt" % "1.2.3")

2. Have this import in your Build.scala file.

import de.johoop.jacoco4sbt.JacocoPlugin._

3. Add the following line in your Build.scala file.

lazy val jacoco_settings = Defaults.defaultSettings ++ Seq(jacoco.settings: _*)

This line adds the jacoco settings to the variable jacoco_settings.

4. Add these settings in to your Play project in Build.scala file as

 val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA, settings = jacoco_settings).settings(
    parallelExecution in jacoco.Config := false)

parallelExecution in jacoco.Config := false makes sure that the ParallelExexution is false during testing.(Look at Point 7)

Note that we’ve a model class with name Test.scala & a test class DemoTest.scala for now.

5. That’s it. Lets run the JaCoCo with command jacoco:cover

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.9.1/jacoco/html

This is how your coverage report would look like :


7. You can check whether the parallel execution if false or not as

Get the CodeCoverage here

About Neelkanth Sachdeva

Project Manager @ eCIFM Solutions Inc. Previous : Senior Software Engineer @ Evernym Inc. Previous : Software Consultant @ Knoldus Software LLP Software Consultant @ Inphina Technologies
This entry was posted in Scala, Web and tagged , , , . Bookmark the permalink.

2 Responses to Integrating JaCoCo in your Play Scala project

  1. Pingback: Building Quality into Scala Development | Knoldus

  2. thetrav says:

    have you worked out how to apply the scala bytecode filters?

    We get large false negatives, and are currently looking for a way to tell SBT to use these filters

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s