My pages Projects Communities java.net
 

JMockit Coverage

How to run tests with code coverage

To gather code coverage metrics for your tests, pass a command line similar to -javaagent:jmockit.jar=coverage=<Coverage arguments>. Note that you should be able to do this inside an Ant target or in a test run configuration for your Java IDE of choice, using either JUnit or TestNG.

Coverage arguments consist of up to four different arguments, in the format classSelectionRegex:outputFormat:outputDir:srcDirs, as follows.
classSelectionRegex specifies the classes to be selected for coverage outputFormat specifies the format for the coverage output, and should be one of: xml, xml-nocp, html, html-nocp outputDir specifies the destination directory for coverage output srcDirs is only applicable to the HTML reports, and is a comma-separated list of Java source directories

The classSelectionRegex argument should be a java.util.regex-conformant regular expression specifying the classes and/or packages in production code for which coverage is desired. For example, "orderMngr.domain.*" selects all classes in the orderMngr.domain package as well as in any sub-packages.

The first two outputFormat values above indicate you want XML output, while the other two indicate the generation of an HTML report. The "-nocp" suffix stands for "no call points", meaning that information on call points will not be included, which usually makes the output much smaller.

Each of these four arguments have a sensible default, so that you won't always have to specify them all.
If classSelectionRegex is empty, then coverage will be applied only to the classes defined in the packages which contain the tests executed in the test run. If no outputFormat is specified, html-nocp is assumed. If outputDir is empty, the current working directory is assumed, with a "coverage-report" subdirectory being created for the HTML report (if not already existing). The srcDirs can also be empty, in which case all "src" directories under the current working dir are automatically found and searched for ".java" sources.

Finally, if no coverage arguments at all are provided then all the defaults described above are used. This is particularly useful when running the tests with JDK 1.6, since simply having coverage.jar in the classpath will cause it to be used.


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser