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.

Tip

Cobertura uses asm to instrument the bytecode. The asm framework is a Java bytecode manipulation and analysis framework. Visit http://asm.ow2.org/ 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 ...

Get Mastering Unit Testing Using Mockito and JUnit 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.