Play Framework (Java, 2.3x) code coverage

I wanted to add code coverage to help me spot additional tests to write. Jacoco4sbt came up in the Google searches as the most likely solution to use. After a first attempt which just didn’t look promising I eradicated Jacoco from my project. I decided to try again after a while and, hey presto, it worked!

The two vital ingredients were:

https://github.com/sbt/jacoco4sbt/wiki

http://stackoverflow.com/questions/20480820/using-jacoco4sbt-with-play-2-2-x-with-alternate-conf-file

I added

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

to project/plugins.sbt and

jacoco.settings

to build.sbt plus I wanted jacoco to use my testing configuration file.

testOptions in jacoco.Config += Tests.Setup( () => System.setProperty("config.file", "conf/testing.conf") )
parallelExecution in jacoco.Config := false

to build.sbt as well, with the blank lines included like that.

Then I ran

./activator jacoco:cover

When I saw the test debug log output in the application.log file I was most surprised and delighted.

Advertisements

Leave a comment

Filed under Uncategorized

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s