How to add code coverage in Play 2 using Jacoco
Code Coverage measures how many lines/blocks of your code are executed while the automated tests are running. Code coverage analysis is a powerful tool for finding more of the bugs that most likely do exist in your software – whether you are aware of them or not. As such, a code coverage analysis tool can help you find more programming errors, which enables you to release a software product of better quality.
Start by creating a new Play 2 application:
Then choose to create a simple Java application.
After this you need to edit your
At the end you see that the Jacoco sbt plugin has been added.
Then you need to configure the Jacoco plugin so it fits in Play 2. Create a file called
qa.jacoco.sbt in the root folder of your project:
Now we have all the configuration in place so you can now start the play console and run code coverage analysis in your project:
When the jacoco command completes you can open your code coverage report generated under target/jacoco/html/index.html.
You should see something similar to this:
Versions used in this article: