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 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:
Create a
pom.xml
file and place it under/Chapter05/Chapter05
.Modify the
pom...