Book Image

Mastering Unit Testing Using Mockito and JUnit

By : Sujoy Acharya
Book Image

Mastering Unit Testing Using Mockito and JUnit

By: Sujoy Acharya

Overview of this book

Table of Contents (17 chapters)
Mastering Unit Testing Using Mockito and JUnit
About the Author
About the Reviewers

Working with the Maven Cobertura plugin

Maven has a Cobertura plugin to measure code coverage; this section will explain how to configure the Cobertura Maven plugin in your project.


Cobertura uses asm to instrument the bytecode. The asm framework is a Java bytecode manipulation and analysis framework. Visit for asm details. Cobertura modifies the .class file, imports net.sourceforge.cobertura.coveragedata.*, implements the HasBeenInstrumented interface, and adds code to capture coverage, such as ProjectData.getGlobalProjectData().getOrCreateClassData("com.packt.coverage.Metrics").touch(21);.

After instrumenting the bytecode, Cobertura creates a .ser file and updates the file during test execution. This .ser file contains the test coverage details. The instrumented bytecode can be slightly slower than normal without it.

Follow the ensuing steps to configure Maven to generate a Cobertura report:

  1. Create a pom.xml file and place it under /Chapter05/Chapter05.

  2. Modify the pom...