JaCoCo

Java Code Coverage (JaCoCo) is a well-known tool for measuring test coverage. To use it in our project, we need to add a few lines to our Gradle configuration file, that is, build.gradle:

  1. Add the Gradle plugin for JaCoCo:
apply plugin: 'jacoco'
  1. To see the JaCoCo results, run the following from your command prompt:
gradle test jacocoTestReport
  1. The same Gradle tasks can be run from the Gradle Tasks IDEA Tool Window.
  2. The end result is stored in the build/reports/jacoco/test/html directory. It's an HTML file that can be opened in any browser:

Further chapters of this book will explore code coverage in more detail. Until then, go to  ...

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.