Introduction to Cover Reports Contributor tasks - generate and upload reports bundles
Cover Reports data, referred to as "reports bundles", are generated and uploaded using Cover CLI (as part of a developer's process) and/or Cover Pipeline (as part of a CI workflow/pipeline).
Java project config (JaCoCo) - how to configure your Java projects to generate JaCoCo reports, essential for use with Cover Reports.
Generate and upload reports bundles - how to use the dcover commands to generate and upload reports bundles.
- how to use authentication for your uploads (if enabled by your Cover Reports Administrator).
This set of topics is targeted at Cover Reports Contributors.
How to use authenticated uploads for reports bundles
By default, any Diffblue Cover user can upload reports bundles to Cover Reports. However, your Cover Reports Administrator may have restricted access using upload authentication. Contact your Cover Reports Administrator for details of what restrictions may be in place and any associated username and password needed for uploads.
Once upload authentication has been enabled you will need to use the --report-username and --report-password options in Cover CLI and Cover Pipeline when uploading reports bundles. The username and password must match those configured by your Cover Reports Administrator.
Authenticated uploads using dcover create:
Authenticated uploads using dcover upload:
If you don't want to supply the --report-username and --report-password options each time you upload reports bundles, you can use the following environment variables instead:
DIFFBLUE_COVER_REPORTS_USERNAME
DIFFBLUE_COVER_REPORTS_PASSWORD
As with the command line options, these variables must match the username and password configured by your Cover Reports Administrator.
dcover create
--coverage-reports
--upload=http://cover-reports-service:8080
--report-username="myusername"
--report-password="mypassword"dcover upload http://cover-reports-service:8080
--report-username="myusername"
--report-password="mypassword"Java project configuration required to generate JaCoCo report files for use with Cover Reports
JaCoCo reports are an essential component of Cover Reports. Some projects have access to a version of JaCoCo that Cover can use, either through their original configuration or via Cover itself (using Maven). However, if Cover cannot find a suitable JaCoCo configuration (typically detected during Preflight checks), the following minor configuration update for your projects to add the appropriate dependencies and plugins (if you're not already using JaCoCo) should be sufficient.
Add the following declarations to the pom.xml file for the project. The dependency ensures that JaCoCo is available for Cover to use for coverage and reporting analysis. The plugin below configures the JaCoCo plugin to provide reporting information when running tests on the project.
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
</dependency><plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
Add the JaCoCo plugin to your build script (build.gradle or build.gradle.kts):
Include the following configuration to enable the generation of the XML reports:
To ensure that you run JaCoCo, we recommend adding finalizedBy jacocoTestReport to your test configuration, for example:
Add the JaCoCo plugin to your build script (build.gradle or build.gradle.kts):
Include the following configuration to enable the generation of the XML reports:
finalizedBy jacocoTestReportapply plugin: 'jacoco'jacocoTestReport {
dependsOn test
reports {
xml.required = true
csv.required = true
}
}test {
finalizedBy jacocoTestReport
}plugins {
jacoco
}tasks {
jacocoTestReport {
dependsOn(test)
reports {
xml.required.set(true)
csv.required.set(true)
}
}
}test {
finalizedBy jacocoTestReport
}How to generate/create and upload reports data/reports bundles
Cover Reports data, referred to as "reports bundles", are generated as part of your code development process and uploaded to Cover Reports. This can be done from Cover CLI and/or Cover Pipeline, using the appropriate dcover commands detailed in this topic. Reports bundles are comprised of the following files:
report.json - Diffblue's coverage report.
diffblue-tests-jacoco-report.xml - a JaCoCo coverage report providing data for Diffblue tests (created by Diffblue Cover).
manual-tests-jacoco-report.xml – a JaCoCo coverage report providing data for manual tests (created by a developer).
Reports bundles can be generated and uploaded as follows:
- integration with Cover Pipeline reporting on the baseline tests, after-merge or periodically.
- create tests, generate the reports bundle, and upload the bundle to the Cover Reports server.
- generate the reports bundle only, no tests created, no upload.
The associated dcover commands can be run from Cover CLI or integrated into your CI/CD workflow/pipeline as needed.
You can also omit the <reports-server> parameter if you prefer to specify the upload url via environment variable instead. For example:
For information about integrating Cover Reports into Cover Pipeline please see.
This topic details the dcover command to create tests, generate the reports bundle, and upload the bundle to the Cover Reports server. Note that Cover Reports is primarily focused on reporting the full test suite and so this approach is not recommend in combination with the create --patch-only option.
Prerequisites:
Configure your project to generate JaCoCo files (see ).
Ensure that Diffblue generated tests are correctly tagged, using the latest version of (see ).
Build your project.
Command details:
Run the following dcover command:
For example:
Optional JaCoCo arguments:
Examples (using default values):
Generate the reports bundle only - no tests created, no upload to the server. This can be useful if tests have already been created for the project using dcover create, but the --coverage-reports option wasn't included.
Prerequisites:
Configure your project to generate JaCoCo files (see ).
Command details:
Run the following dcover command:
Once the reports bundle has been generated, you can upload the bundle to your Cover Reports server using dcover upload - see below.
Additional JaCoCo arguments:
Examples (using default values):
Upload an existing reports bundle only. This can be useful when the reports bundle has been generated separately, but not uploaded.
Command details:
Run the following dcover command:
For example:
Additional JaCoCo arguments:
When generating, naming, and uploading reports bundles, consider the following. You may also wish to discuss these with your Cover Reports Users and Cover Reports Administrators as appropriate.
Generate & Upload - Timing: You can generate and upload reports bundles before, during, and after code development. For consistency, you may wish to define specific schedules and you may also find it useful to generate and upload reports for your project before you run dcover create on the project for the first time (useful for setting a coverage baseline) - see and .
Naming Conventions: The --name, --project-name and --location arguments are used to structure the uploaded data within Cover Reports. Diffblue recommends that you select an appropriate and consistent naming convention to help with data visualization in the Cover Reports UI. Alternatively, don't use these options and allow the data to be auto-generated.
--class-name-template="${CLASS_NAME}<string>"
Used to define a custom test class naming convention to identify tests written by Diffblue Cover. If this argument omitted, the default value of *DiffblueTest will be used
Authentication: If upload authentication has been enabled by your Cover Reports Administrator, you'll need to use the defined username and password when uploading your reports bundles. See Authenticated uploads for details.
--coverage-reports
Generates the reports bundle.
--upload=<reports-server>
Uploads the reports bundle to the specified Cover Reports server. See your Cover Reports Administrator for details, if needed.
--name=<name-of-report>
Sets the name of the reports bundle. Replace <name-of-report> with a useful name. If the --name argument is omitted, the name will default to the current timestamp, or the latest commit hash when used within Git.
--project-name=<name-of-project>
Sets the specific name of the project to which this reports bundle relates. Replace <name-of-project> with a useful name. If the --project-name argument is omitted, the project name in Cover Reports will default to the project name defined by the build system, which is recommended.
--location=<report-location>
Sets the path to the project in Cover Reports. Replace <report-location> with a useful value, with folder names separated by dots. If the provided location does not exist it will be created. If the --location argument is omitted, the project will be placed in the default location. Project locations can be changed from within Cover Reports at any time.
--report-username=<username>
--report-password=<password>
Cover Reports username and password. Used for authenticated uploads only - see Authenticated uploads. The username and password must match those configured by your Cover Reports Administrator.
--jacoco-command-diffblue
=<command>
Custom command to generate the JaCoCo report for tests written by Diffblue Cover.
--jacoco-command-manual
=<command>
Custom command to generate the JaCoCo report for manually written tests.
--jacoco-xml-test-report
=<jacoco-xml-test-report>
Filename and path (including the .xml extension) of the JaCoCo report created using custom commands (as defined above).
--jacoco-command-diffblue
=<command>
Custom command to generate the JaCoCo report for tests written by Diffblue Cover.
--jacoco-command-manual
=<command>
Custom command to generate the JaCoCo report for manually written tests.
--jacoco-xml-test-report
=<jacoco-xml-test-report>
Filename and path (including the .xml extension) of the JaCoCo report created using custom commands (as defined above).
dcover upload
<reports-server>
Uploads the reports bundle to the Cover Reports server. Replace <reports-server> with the URL and port number for your server. See your Cover Reports Administrator for help, if needed.
--name
=<name-of-report>
Sets the name of the reports bundle. Replace <name-of-report> with a useful name. If the --name argument is omitted, the name will default to the current timestamp, or the latest commit hash when used within Git.
--project-name=<name-of-project>
Sets the specific name of the project to which this reports bundle relates. Replace <name-of-project> with a useful name. If the --project-name argument is omitted, the project name in Cover Reports will default to the project name defined by the build system, which is recommended.
--location=<report-location>
Sets the path to the project in Cover Reports. Replace <report-location> with a useful value, with folder names separated by dots. If the provided location does not exist it will be created. If the --location argument is omitted, the project will be placed in the default location. Project locations can be changed from within Cover Reports at any time.
--report-username=<username>
--report-password=<password>
Cover Reports username and password, used for authenticated uploads only. The username and password must match those configured by your Cover Reports Administrator.
--jacoco-report-diffblue
=<report>
Filename and path (including the .xml extension) of the JaCoCo report for Diffblue tests (if a non-standard location is used). Optional.
--jacoco-report-manual
=<report>
Filename and path (including the .xml extension) of the JaCoCo report for manually written tests (if a non-standard location is used). Optional.
// Create, Generate, and Upload
dcover create
--coverage-reports
--upload=<reports-server>
// Generate Only
dcover coverage-reports
// Upload Only
dcover upload <reports-server>
// Cover Pipeline Integration (not recommended)
dcover ci create coverage-reports upload <reports-server>export DIFFBLUE_COVER_REPORTS_UPLOAD_URL=<reports-server>
// Create, Generate, and Upload
dcover create --coverage-reports --upload
// Upload Only
dcover uploaddcover create
--coverage-reports
--upload=<reports-server>
--name=<name-of-report>
--project-name=<name-of-project>
--location=<report-location>
--report-username=<username>
--report-password=<password>
--class-name-template=${CLASS_NAME}<string>dcover create
--coverage-reports
--upload=http://cover-reports-service:8080
--name="Branch: 1234/feature-TG12345"
--project-name="hello-world"
--location="customer-markets.trading.name"
--report-username="myusername"
--report-password="mypassword"
--class-name-template="${CLASS_NAME}CreatedTests"// jacoco-command-diffblue for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='*DiffblueTest.java'"
// jacoco-command-manual for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='!*DiffblueTest.java'"
// jacoco-command-diffblue for Gradle
--jacoco-command-diffblue=./gradlew test --tests=*DiffblueTest.java
// jacoco-command-manual for Gradle
// There is currently no simple way to provide an exlusion pattern to Gradle
// via the command line, we suggest using --class-name-template instead// jacoco-command-diffblue for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='*DiffblueTest.java'"
// jacoco-command-manual for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='!*DiffblueTest.java'"
// jacoco-command-diffblue for Gradle
--jacoco-command-diffblue="./gradlew test --tests=*DiffblueTest.java"
// jacoco-command-manual for Gradle
// There is currently no simple way to provide an exlusion pattern to Gradle
// via the command line, we suggest using --class-name-template insteaddcover coverage-reports// jacoco-command-diffblue for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='*DiffblueTest.java'"
// jacoco-command-diffblue for Gradle
--jacoco-command-diffblue=./gradlew test --tests=*DiffblueTest.java
// jacoco-command-manual for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='!*DiffblueTest.java'"
// jacoco-command-manual for Gradle
--jacoco-command-diffblue=./gradlew clean test --tests=!*DiffblueTest.java// jacoco-command-diffblue for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='*DiffblueTest.java'"
// jacoco-command-diffblue for Gradle
--jacoco-command-diffblue="./gradlew test --tests=*DiffblueTest.java"
// jacoco-command-manual for Maven
--jacoco-command-diffblue="mvn clean test jacoco:report -Dtest='!*DiffblueTest.java'"
// jacoco-command-manual for Gradle
--jacoco-command-diffblue="./gradlew clean test --tests=!*DiffblueTest.java"dcover upload <reports-server>
--name=<name-of-report>
--project-name=<name-of-project>
--location=<report-location>
--report-username=<username>
--report-password=<password>dcover upload http://cover-reports-service:8080
--name="Branch: 1234/feature-TG12345"
--project-name="hello-world"
--location="customer-markets.trading.name"
--report-username="myusername"
--report-password="mypassword"