In this section
Introduction
Cobertura is a free, open source Java tool that calculates the percentage of code accessed by unit tests. Cobertura runs produce HTML or XML files indicating what lines of code and branches were tested.
The Parasoft Cobertura Extension transfers Cobertura Java code coverage results to Parasoft (DTP) so that the coverage can be processed and viewed along with other data points. The extension can process output that comes directly from Cobertura, as well as Cobertura-formatted outputs produced by other tools, such as the Istantbul coverage tool.
Cobertura provides coverage information for your unit test cases, but it doesn’t report which test cases achieved what coverage. If test case coverage association is important for your team, contact Parasoft to ask about the coverage capabilities provided by the Parasoft Jtest.
Requirements
- Parasoft Analyzer package must be installed prior to installing the Cobertura extension.
- Oracle Java Runtime 1.8.0 or higher (required to run Parasoft Analyzer package).
- At least one of the following Java and/or JavaScript coverage reports:
- XML coverage reports for Java code coverage in Cobertura format. There are a number of ways to produce a Cobertura coverage report. With Maven, all that is necessary to compile, test and generate a coverage report for a project is to run the following command:
mvn cobertura:cobertura
Other build systems have their own requirements. For more information, see the Cobertura Wiki at https://github.com/cobertura/cobertura/wiki/FAQ.
- XML coverage reports for JavaScript code coverage in Cobertura format. You can generate these reports using the Istanbul open source coverage tool. For more information on Istanbul, see https://github.com/gotwarlost/istanbul.
- XML coverage reports for Java code coverage in Cobertura format. There are a number of ways to produce a Cobertura coverage report. With Maven, all that is necessary to compile, test and generate a coverage report for a project is to run the following command:
Installation
- Unzip the analyzer into the directory where the Parasoft Analyzer package was installed. See the Parasoft Analyzer package documentation.
- Create a plain text settings file with the required settings (see Configuration). We recommend using the provided coberturasettings.properties file as an example of a complete settings file. The file is located in the examples directory of the Cobertura extension distribution. A full list of general settings properties can be found in the documentation provided with the Parasoft Analyzer package.
Usage
- Open a command prompt and navigate to the Parasoft Analyzer package installation root directory.
- Execute the parasofttestcli.bat or parasofttestcli.sh script using the required parameters, e.g., (all one line):
parasofttestcli.sh -Dsettings="C:\sample\cobertura-settings.properties" Ddata.dir="C:\sample\sampleProjectFolder" -Dresults.file=c:\sample\sampleProjectFolder\target\site\cobertura\coverage.xml
Required Parameters
The following settings are required.
-Dresults
This parameter specifies the path to the Cobertura-formatted coverage XML results file. This file is typically located in <project_home>/target/site/cobertura directory. The path should be relative to the -Ddata.dir value. Example configuration:
–Ddata.dir=<project_home>
–Dresults.file=target/site/Cobertura.coverage.xml
You can combine coverage from multiple module projects into a single report by using wildcards to specify the various coverage.xml files. The following example shows how to reference coverage files in sub-projects if the -Ddata.dir
setting points to a top-level project:
–Dresults.file=**/coverage.xml
Multiple result files can also be specified by using result file options that match the regular expression results[0-9]*\.file
. For example, all of these options could be used:
-Dresults.file=… -Dresults1.file=… -Dresults314.file=…
-Dsettings
Path to the settings configuration file (see Configuration).
-Ddata.dir
Specifies the path to the source code of the project that was tested. This is used to collect source control metadata (e.g., authorship, last updated, etc.) for DTP reporting and processing.
Optional Parameters
The following parameter is optional.
-Dparasoft.local.storage.dir
Specifies where log files are generated. The recommended location is ${project.base.dir}/.parasoftanalyzer
.
For example:
-Dparasoft.local.storage.dir=.parasoftanalyzer
Configuration
See the Parasoft Analyzer package documentation for a complete list of configurations.
Required Settings
The following settings are required to run the Cobertura extension.
analyzer.cobertura.enabled
Enables the analyzer. Values are true
or false
.
Example:
analyzer.cobertura.enabled=true
Change Log
The following updates have been made to the Cobertura extension.
Updates for 10.4.1
- Updated Parasoft Test library to 10.4.1
- The DTP Engine Package has been renamed to Parasoft Analyzer package.
Updates for 10.3.4
- Updated Parasoft Test library to 10.3.4
- The DTP Engine Package now uses a Parasoft Test license instead of a DTP license. Contact your Parasoft representative to obtain a Parasoft Test license if you don't have one.
End User License Agreement (EULA)
The Parasoft End User License Agreement (EULA) is available at https://www.parasoft.com/parasoftlicense.