Only this pageAll pages
Powered by GitBook
Couldn't generate the PDF for 332 pages, generation stopped at 100.
Extend with 50 more pages.
1 of 100

Live Docs

Loading...

Get Started

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

EVALUATION & ONBOARDING

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Features

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Phase 2: Developer productivity

In this phase we will teach your developers how to use Cover efficiently and understand the value that you get from Cover.

  1. Getting started using Cover: enable your developers to use Cover efficiently in their daily workflows (CI Pipeline, CLI, IntelliJ plugin).

  2. Introduction to Cover Reports: enable engineering managers to use Cover Reports to assess the value received from Diffblue Cover.

Discover Diffblue Cover

Diffblue Cover is a reinforcement learning AI platform that automatically writes comprehensive, human-like Java unit tests - saving developer time, increasing test coverage, and reducing regression risks. Cover is provided as an IntelliJ IDE plugin, a CLI application, and a CI integration to provide fully autonomous operation. Three additional components, for test management and analytics, complete the Diffblue Cover solution.

Get started

Discover the details

Product specific:

General information:

DevOps

Detailed learning paths targeted at DevOps:

Achievements:

Writing tests

How to write tests using Cover Plugin for IntelliJ

To write tests using Cover Plugin for IntelliJ:

IntelliJ
Action

Module 5: Speed up your test execution

We will show you how to slash test execution times with Cover Optimize in CI and locally.

To start this module you should have completed .

Module 4: Introduction to Cover Reports

We will show you how to use Cover Reports to assess the value received from Diffblue Cover.

To start this module you must have completed .

Project configuration

Before using Cover Plugin to write tests, your project must meet the following general requirements:

  • Java 8, 11, 17, or 21 compatible source code, or Kotlin source code.

  • Maven 3.2.5+ or Gradle 4.9+ build tools.

  • The project must compile and run with no failing unit tests.

Jumpstart

The Diffblue Jumpstart onboarding program ensures that your development teams quickly get value from Diffblue Cover. Our engineers teach your champions how to get the best from Diffblue Cover, help them integrate it into your software development lifecycle, and educate your developers on the best way to work with Diffblue tests.

After having set up the , Jumpstart proceeds in the following three phases.

  1. : help your champions set up Cover on your first projects and enable your champions to roll out to more projects on their own.

  2. : teach your developers how to use Cover efficiently and understand the value that you get from Cover.

Reset Cover Plugin settings

How to reset Cover Plugin to its default settings.

Cover Plugin Settings

To reset Cover Plugin Settings:

  1. Open the Cover Settings panel in the IntelliJ IDE.

Method Annotations

To suppress compiler warnings for test methods written by Diffblue Cover, go to Diffblue > Change Settings > Method Annotations and update the Warnings to suppress list, as needed. The warnings or warning types defined here will be added to all test methods written by Diffblue Cover (as detailed below) using the @SuppressWarnings code annotation. This is especially useful when using SonarQube - see .

Example - all: all

Suppresses all warnings - adds the code annotation @SuppressWarnings({"all"})`

Example - types: unused,raw-types

All associated dependencies have been added, including JUnit or TestNG testing frameworks.

Also, Diffblue Cover requires that the system environment (hardware, operating system, network connectivity, Java installation) as well as the project environment (build tooling, dependencies, presence of artifacts, existing unit tests) meet the minimum requirements as detailed in Specs & Reqs. Cover Plugin will perform an environment check before analysis begins to ensure that the requirements are met - if there are any issues, these will be reported via the Diffblue Cover panel in IntelliJ using E (Environment) Output Codes.

Note that you can run dcover create --preflight (using Diffblue Cover CLI) to check the Cover prerequisites for your project, without performing any other actions.

Module 2
Module 1

Advanced topics (optional): tips and tricks to write more tests with Cover and improve the testability of your codebase as well as slash test execution times on your Pull Requests.

prerequisites
Up and running
Developer productivity

What is Diffblue Cover?

Familiarize yourself with the features, functions, and capabilities of Diffblue Cover.

Free-Trial

Trying out Diffblue Cover for the first time? Get up and running with Cover Plugin for IntelliJ and Cover CLI – download, install, license, and play.

Get Started

Get started with Diffblue Cover, from your first AI-created Java unit test, to analyzing your code coverage, and more.

Cover

Automatically write unit tests for your methods and classes directly in IntelliJ.

Cover

Automatically write unit tests for your project using the command line.

Cover

Integrate Cover CLI directly into your source code control / CI Pipeline.

Cover

Visualize and manage your test coverage.

Cover

Automatically refactor code to make it more testable and increase coverage.

Cover

Run only the unit tests that apply to your code change, reducing CI time and cost.

Specs & Reqs

Output Codes

Licensing

Improve Code Coverage

Update Cover

Cover Editions

Suppresses one or more "warning types" - this example adds the code annotation @SuppressWarnings({"unused","raw-types"})

Example - specific: java:S1161

Suppresses one or more specific warnings (using warning codes) - this example, adds the code annotation @SuppressWarnings({"java:S1161"}

Using SonarQube with Cover Plugin

Module 2: Cover Pipeline CI integration

In this module we are going to help you integrate Cover Pipeline into the CI system of your first projects.

You will learn about Cover's Reference Deployments and decide which one is the best fit for you. We will then guide you towards the implementation of the chosen deployment.

Phase 1: Up and running

This phase will help your champions set up Cover on your first projects and enable your champions to roll out to more projects on their own.

  1. Create your Cover unit test baseline: validate the build configuration of your first projects with respect to unit testing and write a test baseline for your first projects.

  2. Cover CI Pipeline integration: integrate Cover into the CI system of your first projects.

Spring configuration options

Spring configuration options for Diffblue Cover Plugin for IntelliJ.

To set your Spring configuration options for Cover Plugin go to Diffblue > Change Settings > Spring in IntelliJ.

Mocking in Spring integration tests

Check the Enable integration tests option to limit mocking for Spring projects to Repository dependencies only - Spring handles the rest directly. If this option is not selected then mocking may be implemented for a wider scope of dependencies.

  • Spring Repositories are classes implementing org.springframework.data.repository.Repository or those annotated with org.springframework.stereotype.Repository.

  • This option is not applied when creating tests for @Controller classes.

Spring contexts

Check the Use Spring contexts option to enable Spring contexts for dependency injection in tests written by Diffblue Cover.

Spring Boot Tests

Check the Use Spring Boot to write tests option for dependency injection using, amongst the others,@MockBean. If this option is not enabled Cover will instead fall back to other dependency injection mechanisms for tests such as Mockito's @InjectMocks and @Mock. This option may be useful depending on whether or not a Spring context needs to be loaded for a particular unit test suite.

Note: This functionality is in Beta stage, hence there could be cases where some inconsistencies and limitations might still be present.

Active profiles

Use the Active Profiles text box to specify one or more Spring profiles to activate while writing tests (comma separated list). If no profiles are defined, Cover will automatically use the test profile (if available), otherwise the default Spring profile will be used.

Environment Check Cache

A part of writing tests is to determine whether the environment is configured correctly. This environment check is performed immediately before writing tests and can take some time.

Since the environment does not change that often, Cover will cache the results of a check and reuse the results in subsequent write test operations. This helps to deliver tests faster.

If some of the properties of the environment change, the cache will be automatically invalidated and Cover will run a new check the next time tests are written.

Clearing the Environment Check Cache

It is possible that occasionally changes to the environment are not detected by Cover and the cache will be used when it shouldn't be.

In this case, an error will be shown when writing tests. To clear the cache and force Cover to check the environment either:

  • Select the Clear Environment Check Cache option from the main Diffblue menu

  • Press the Clear Environment Check Cache button in the Diffblue Cover tool panel

The next write tests operation will then check the environment for changes.

Phase 3: Advanced topics

In this phase we will enable you to make use of advanced functionality of Cover.

  1. Speed up your test execution: slash test execution times with Cover Optimize in CI and locally.

  2. Getting more from Cover: tips and tricks to write more tests with Cover and improve the testability of your codebase.

Module 3: Getting started using Cover

We will enable your developers to use Cover efficiently in their daily workflows (CI Pipeline, CLI, IntelliJ plugin) on your first projects.

To start this module you must have completed Phase 1.

Know how to activate and configure Cover Pipeline within your chosen CI/CD tool - initial setup and additional config options.
  • GitHub

    Integrate the Diffblue Cover Action into your GitHub workflows.

    GitLab

    Incorporate the Diffblue Cover Project Integration into your GitLab pipeline.

    Other CI

    Integrate Cover CLI into your CI pipeline workflow - Jenkins, Azure, AWS.

    Right-click a method or class and select Write Tests.

    Select Run > Edit Configurations from the IntelliJ menu.

    Once started, if you need to cancel the test writing process at any point, click the red Stop button in the Cover Plugin tool window.

    In general, if the Write Tests option is available then Cover Plugin can write tests for your methods or classes. However:

    • If it is not possible for Cover to write a complete test, instead a partial test may be created - see Creating partial tests.

    • If you don't want to write a complete test, Cover Plugin can help set up your tests by creating a skeleton test instead - see Creating skeleton tests.

    Editor Panel

    Click the Write Tests gutter icon.

    Editor Panel

    Right-click a method or class and select Write Tests.

    Editor Panel

    Select Diffblue > Write Tests from the IntelliJ menu.

    Project Tool Window

    Right-click a folder or file and select Write Tests.

    At the bottom of the Test Creation Tab, select the 'Restore Test Creation Settings' button to reset settings.\
    Note: The 'Restore Default Test Creation Settings' button will not be selectable if the currently applied settings are already default.

    Project settings

    To remove any project specific settings:

    1. Open the project in the IntelliJ IDE and navigate to .idea folder in the project.

    2. Delete the CoverSettingsProjectConfig.xml file, if present.

    What is Diffblue Cover?

    Diffblue Cover is a reinforcement learning AI platform that automatically writes comprehensive, human-like Java unit tests for Java and Kotlin projects - saving developer time, increasing test coverage, and reducing regression risks. Cover is provided as an IntelliJ IDE plugin (Cover Plugin), a CLI application (Cover CLI), and a CI integration to provide fully autonomous operation (Cover Pipeline). Three additional components (Cover Reports, Cover Optimize, and Cover Refactor), for test management and analytics, complete the Diffblue Cover platform.

    But what does that mean in practical terms? As an example, let's take a method for uploading a file to an Amazon S3 bucket. The method is relatively simple, just a few lines of code, but the required test is more complex and would take a developer approximately 30 minutes to write if they've never done it before. Diffblue Cover did this in 1.6 seconds - that's not a typo - 1.6 seconds, computationally perfect, human readable, every pathway tested.

        public PutObjectResult uploadFileToBucket(String bucketName, String key, File file) {
            try {
                return s3client.putObject(bucketName, key, file);
            } catch
    
    @ContextConfiguration(classes = {AmazonService.class})
    @ExtendWith(SpringExtension.class)
    class AmazonServiceDiffblueTest {
        @MockBean
        private AmazonS3 amazonS3;
    
        @
    

    Taking another real-world example from an existing customer we can illustrate how this is scaled up for an organization. Diffblue Cover was able to write 3,000 unit tests across an expansive code base for a single mission-critical application, right out of the box. A conservative estimate is that this would have taken a senior developer an estimated 268 developer days to write. Diffblue Cover achieved this in 8 hours, doubling test coverage, even before any refactoring.

    Some basics

    If you missed our short intro video on the website, take a look here - this captures the essentials of Diffblue Cover:

    Key features

    Diffblue Cover is the generative AI engine at the center of our platform. Cover automatically writes human-like Java unit tests that are easy for a developer to read and understand. AI-written unit tests are ready to use - they compile, run, and accurately validate the current behavior of your code.

    Cover is fully autonomous. It can create an entire unit test suite for your whole application in a single execution, run locally within your environment, no cloud service required, no developer overhead. Cover also maintains this unit test suite as your software evolves, even on applications with millions of lines of code. Thanks to a deep understanding of how your code works, Diffblue Cover knows what tests need to be added and updated for every code change. It implements the necessary updates automatically, ensuring coverage doesn’t dip while your teams move faster.

    IDE, CLI, CI Pipeline

    Diffblue Cover is one AI, provided in three interaction models - an IDE plugin (Cover Plugin) and a CLI tool (Cover CLI) for developer use, and a CI Pipeline integration (Cover Pipeline) for DevOps teams. Use Cover Plugin, CLI, and Pipeline in isolation or in partnership as needed, depending on your preferred workflow.

    • Cover Plugin for IntelliJ writes tests for your methods and classes directly within the IDE on the developer desktop.

    • One click test creation, fully integrated UI.

    Report, Optimize, Refactor

    Three additional features are provided to allow you to monitor your test coverage (Cover Reports), optimize test runs (Cover Optimize), and automatically refactor your code to improve testability (Cover Refactor).

    • Visualization tool for test coverage statistics, coverage risk, testability, and more.

    • Get valuable insights about your Java codebase - pinpoint unique, actionable insights that improve quality and efficiency.

    • Have a more holistic view of unit testing. Coverage data is combined with information on variables like code quality, testability. and complexity.

    Key benefits - in summary

    It's difficult to summarize all the benefits of Diffblue Cover, but here's our top ten:

    • Automated Java unit tests. This one's a given. Automatic, unbiased unit tests that exercise the actual behavior of your code, including obscure corner cases and scenarios developers may not know how to test.

    • Eliminate developer overhead. Avoid researching tests, writing tests, maintaining tests, learning unfamiliar code source, context switching, waiting time, and more. Target your developer skills at improving your applications instead.

    • Catch regressions early and at the most granular level. Avoid rework time, optimize workflows, and avoid outages in the field.

    How it works

    • Diffblue Cover first ensures that your code is compiled and examines each method that Cover will create tests for, and any related methods.

    • Cover then creates initial test candidates for each method, which are then evaluated and adjusted to maximize test coverage. This process is repeated until the set of tests that optimize coverage are selected and committed to your code base. The tests are computationally correct and human readable, every time.

    • Diffblue Cover is intended to be used for unit regression testing. That means it creates tests that reflect the current behavior of your code. Later, when you make changes to the code, these tests may fail and therefore highlight regressions. Since tests are written for your entire application at the most granular level, this means the smallest of regressions are caught which can avoid the dangers of incubated regressions that can manifest and build over time.

    Reference Deployments

    A Cover deployment consists of multiple components (Plugin, CLI, Pipeline, Reports), which need to be installed and configured to interact with your CI/CD infrastructure and among each other correctly.

    We strongly recommend to strictly follow below reference deployments as deviations from them can lead to a dysfunctional deployment.

    Depending on the properties of your CI/CD system, Cover can integrate in a few different ways so that you get most from your Cover deployment:

    1. No CI/CD System Available: This is the most basic deployment which does not make use of a CI/CD system and thus entails most manual effort.

    2. : This deployment is suitable if you are not ready for creating tests in your CI/CD system, but still want to benefit from automated reporting.

    3. : This deployment is suitable if your CI/CD system tends to be slow on pull requests.

    4. : If your CI/CD system tends to be fast on pull requests then you can take advantage of writing and updating new tests on each pull request.

    Reference Deployment 1: No CI/CD System Available

    This is the most basic deployment which does not make use of a CI/CD system and thus entails most manual effort. You have to trigger all actions manually from developer workstations. See diagram below.

    You need to on a central server and and on developer workstations. is configured on developer workstations so that you can track Diffblue usage.

    The developer onboarding a new project creates the initial test baseline using Cover CLI and uploads coverage data to Cover Reports. On each Cover release, a developer refreshes the baseline using Cover CLI and uploads coverage data to Cover Reports in order to track test coverage across your projects. Developers use Cover Plugin day-to-day to write and update tests.

    Reference Deployment 2: Minimal CI/CD System

    This deployment is suitable if you are not ready for creating tests in your CI/CD system, but still want to benefit from automated reporting. See diagram below. The difference to Reference Deployment 1 is that it automates uploading coverage data to Cover Reports, enabling more frequent tracking of test coverage across your projects.

    You need to on a central server and and on developer workstations. is configured on developer workstations so that you can track Diffblue usage.

    The developer onboarding a new project creates the initial test baseline using Cover CLI and uploads coverage data to Cover Reports. Developers use Cover Plugin day-to-day to write and update tests. CI is configured to run periodically, e.g. nightly, on the stable branch, e.g. main, of the project to create and upload coverage reports to Cover Reports in order to track test coverage across your projects. On each Cover release, the baseline is refreshed using Cover CLI and coverage data uploaded to Cover Reports.

    Reference Deployment 3: Slow CI/CD System

    This deployment is suitable if your CI/CD system tends to be slow on pull requests. See diagram below. The difference to Reference Deployment 2 is that

    • test baselines are triggered automatically and refreshed more frequently, and

    • coverage data is automatically uploaded to Cover Reports on merging pull requests.

    You need to on a central server, in your CI/CD system and and on developer workstations. is configured on developer workstations and in your CI/CD system so that you can track Diffblue usage.

    The developer onboarding a new project creates the initial test baseline using Cover CLI and uploads coverage data to Cover Reports. Developers use Cover Plugin day-to-day to write and update tests. Coverage data is uploaded to Cover Reports whenever a pull request is merged in order to track test coverage across your projects. CI is configured to run periodically (e.g. weekly) to refresh the baseline and to upload coverage data to Cover Reports.

    Reference Deployment 4: Fast CI/CD System

    If your CI/CD system tends to be fast on pull requests then you can take advantage of writing and updating new tests on each pull request. The difference to Reference Deployment 3 is that tests are added incrementally in the pull request workflow.

    You need to on a central server, in your CI/CD system and and on developer workstations. is configured on developer workstations and in your CI/CD system so that you can track Diffblue usage.

    The developer onboarding a new project creates the initial test baseline using Cover CLI and uploads coverage data to Cover Reports. Developers use Cover Plugin day-to-day to write and update tests locally. When developers push their code then Cover writes new tests that developers haven't written locally, updates existing ones and commits the changes to their pull request branch. Coverage data is uploaded to Cover Reports whenever a pull request is merged in order to track test coverage across your projects. CI is configured to run periodically (e.g. weekly) to refresh the baseline and to upload coverage data to Cover Reports.

    Licensing

    How Diffblue Cover is licensed and where to find licensing resources

    Activate a license

    Follow these steps to activate a license. Note that:

    • Cover Plugin Community Edition is free to use but does require product verification to activate your perpetual license.

    • These steps cover online license activation only.

    • Offline licensing for Cover CLI is available for Diffblue Cover Enterprise Edition only - see and .

    Once you install Cover Plugin for IntelliJ, you'll be prompted for your license key to activate the plugin. Alternatively, the license can be activated at any time from the IntelliJ toolbar Diffblue > Activate License.

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, see .

    To check your current license details, go to the IntelliJ toolbar Diffblue > View License Information.

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, as well as details of offline licensing (Enterprise Edition only), see .

    Online & Offline

    Online license activation

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. To perform the license check Diffblue Cover needs an active internet connection to the following servers:

    • https://licensing.diffblue.com/

    • https://api.licensespring.com/

    The license check uses this connection to identify individual devices. Further details regarding the exact data exchanged are available in the .

    For more details, including troubleshooting, see the main topic.

    Offline license activation

    Diffblue Cover Enterprise Edition users with the offline option can activate 100% offline. This means Diffblue Cover can be used in secure and air-gapped environments with no external network connection required.

    For more details, including troubleshooting, see the main topic.

    Editions

    Diffblue Cover is licensed according to the four which determine what features and limits apply to your use of Diffblue Cover. Please see for more details.

    Diffblue license manager

    According to the terms of your subscription, you may be given access to the allowing you to see license use, manage license keys, and license users. License manager access is granted according to the exact license type purchased - it may not be applicable to your license type.

    Update Cover

    How to update Cover Plugin and Cover CLI to the latest version

    Diffblue releases product updates about every two weeks to continuously provide you with product enhancements and new features. Note that:

    • If needed, check the details for the latest updates, and even the older ones - see What's new.

    • When you update, you'll always be updated to the latest version.

    • If you're using Cover Plugin and Cover CLI, we recommend that you update both products to the latest version.

    Updating Cover Plugin may take a few minutes to complete and will require an IDE restart - you won't be able to create any tests for your projects while the update is progressing.

    1. In IntelliJ, go to File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS), highlight the Diffblue Plugin and click Update in the details panel.

    Updating Cover CLI may take a few minutes to complete and you won't be able to create any tests for your projects while the update is progressing.

    Windows:

    1. Using the link provided by Diffblue, download the new Diffblue Cover CLI file - either the .exe installer or .zip archive, as needed.

    Note: To update Cover Reports, see .

    Developer

    Detailed learning paths targeted at developers:

    Achievements:

    Proof of Value

    Diffblue’s Proof of Value (PoV) program aims to enable technical evaluation of Diffblue Cover in the context of the expected business value.

    It is designed to be an in depth opportunity to learn about our autonomous AI-powered unit testing solution and to help customers validate their technical architecture and business processes in order to be able to effectively evaluate Diffblue Cover.

    The solution, its practical application, and how it drives specific business value according to the specific use case you have in mind (examples below) are proven and documented throughout the PoV process.

    Advantages of working with the Diffblue PoV program

    Our Proof of Value (PoV) exists to achieve the following.

    • Help potential customers get the most out of Diffblue Cover in the shortest amount of time possible whilst understanding how it is like to work with Diffblue as a partner.

    • Demonstrate the business value and tangible benefits of Diffblue Cover.

    • Quantify efficiency gains, cost savings & other benefits that the solution brings.

    The Diffblue PoV Program provides several advantages for potential customers looking to evaluate Diffblue Cover including the following.

    • Direct access to Diffblue resources, tools and expertise to help customers accelerate their deployment and adoption.

    • Ensures that potential customers are successful by providing guidance and best practices from Diffblue Solutions Architects.

    • Builds a strong business case, by quantifying specific product benefits and aligning them with strategic objectives.

    This guide is specifically intended as an overview of our PoV process and to help set expectations.

    Goal

    With the Difflblue Cover Proof of Value program, we aim to identify your best deployment path to leveraging autonomous AI-powered unit test generation for your team/engineering organization and to demonstrate product value.

    The goal is not to implement a complete product installation & process workflows. Instead, it’s intended to test and validate assumptions related to process, the core AI-driven technology and to demonstrate that the core feature capabilities are valuable.

    Specifically, the goal is to prove that Diffblue Cover:

    • writes high quality unit tests at scale,

    • writes understandable human-like unit tests that compile,

    • effectively prevents regressions, and

    • significantly saves developer time/resources.

    Test coverage

    Improve, monitor, and manage your test coverage:

    Achievements:

    Get started

    Get started with Diffblue Cover - Plugin, CLI, Pipeline, Reports.

    To get started with Diffblue's GitLab or GitHub integrations, see Cover Pipeline for GitLab or Cover Pipeline for GitHub.

    Demo code, statistics, and timings used throughout Diffblue docs and eLearning videos are based on in-house demonstrations. These may differ slightly from those experienced within a live production environment.

    Get started

    Get started with Diffblue Cover - download, install, license, and play:

    Achievements:

    Menu options

    Where to find the Write Tests menu option and how it can be used

    The Write Tests menu option can be used throughout IntelliJ:

    • Right click in the Project Tool Window.

    • Right click in the Structure Tool Window.

    • Right click in the Text Editor.

    • Use the .

    The Write Tests menu option will create tests for your methods and classes but each menu option works slightly differently to produce tests for different parts of your code.

    Project Tool Window

    When navigating through your project, you'll likely use the project tool window in IntelliJ. Right-click on any of the elements and select Write Tests. Diffblue Cover will attempt to write tests for everything it can find within that package (license limitations may apply).

    You can also select multiple classes with Shift or CTRL (CMD on MacOS). Cover will attempt to write tests for every class within your selection.

    Structure Tool Window

    Similar to the Project Tool Window, IntelliJ provides a Structure menu to help you navigate around your codebase. In particular, the structure menu will show classes, methods and other elements in the currently open file. As with the Project Tool Window, right-click on any method in the Structure Tool Window and select Write Tests, and you can also select multiple methods with Shift or CTRL (CMD on MacOS).

    Text Editor

    In the IntelliJ editor panel, you can right-click a method or class to display the Write Tests menu option - an alternative to the gutter icon, but also allows you to right-click anywhere within a class or method.

    The menu option is also available when making one or more editor selections.

    Diffblue Menu Bar

    The Write Tests menu option is also available from the Diffblue menu bar. This will perform the exact same function as the menu option in the text editor.

    Using SonarQube with Cover Plugin

    Tips for successfully using SonarQube with Cover Plugin for IntelliJ.

    Tests written by Diffblue Cover may be reported as "code smells" by SonarQube. To suppress these warnings and reduce the reported "code smells" in the SonarQube output, go to Diffblue > Change Settings > Method Annotations and update the Warnings to suppress list, as needed - this will add the @SuppressWarnings code annotation to all test methods written by Diffblue Cover, as detailed below.

    Example - all: all

    Suppresses all warnings - adds the code annotation @SuppressWarnings({"all"})`

    Example - types: unused,raw-types

    Suppresses one or more "warning types" - this example adds the code annotation @SuppressWarnings({"unused","raw-types"})

    Example - specific: squid:S2699

    Suppresses one or more specific warnings (using warning codes) - this example, adds the code annotation @SuppressWarnings({"squid:S2699"}

    If you want to configure SonarQube directly, please see

    Writing tests

    How to automatically write Java unit tests using Cover CLI

    To write tests using Cover CLI:

    • To write tests for your entire project, open Windows PowerShell (Windows) or Terminal (macOS/Linux), navigate to your project, and enter the command dcover create

    • To restrict tests to an individual package, class, or method, specify one or more entry points on the command line using dcover create [<entryPoint>...] - for example, dcover create io.diffblue.corebanking.account.Account.

    • For a quick summary of core Cover CLI commands, see . For full details - every command, every argument, every option - see .

    • In general, dcover create will write complete tests for your methods, classes, modules, and projects. However, Cover is not always able to create a complete test, instead it may only be able to create partial tests - see .

    • Once Diffblue Cover starts to run, you can cancel the operation at any point by pressing CTRL-C.

    Covering all enum values

    The Diffblue Cover Plugin for IntelliJ can write tests which ensure that all values of an enum are covered when an enum is passed as an argument or returned from a method.

    Cover Plugin for IntelliJ can write tests which ensure that all possible values of an Enum type are covered by the test suite, when that Enum is passed to a method as an argument or is a return value of a method.

    With and without "Cover all enum values"

    To understand the difference that the Cover all enum values feature makes to created tests, we can write tests on a simple class which takes an Enum

    Senior developer

    Use Cover Reports to monitor and manage test coverage.

    Creating partial tests

    By default, creation of partial tests is enabled in the Diffblue Cover Plugin for IntelliJ. This page covers partial tests and their uses, and how to turn off this option.

    About partial tests

    Normally, selecting or Write Tests will create complete tests for a method. A complete test consists of Arrange, Act, and Assert sections and passes when executed. However, sometimes Diffblue Cover is not (yet) able to write complete tests and will give the reason for not producing complete tests in the Diffblue Cover tool window. In these cases, Diffblue Cover will create partial tests - these tests may be incomplete in various aspects:

    Test Directory

    How to locate the tests created by Cover Plugin for IntelliJ, within your project.

    The tests created by Cover Plugin for IntelliJ will be placed in a location within the project according to the following:

    1. If a test source directory (e.g src/test/java) exists in the current project module, Cover Plugin will add the tests there.

    2. If no existing test source directory could be found for the current project module, Cover Plugin will add tests to src/test/java in the same module as the class for which tests are written (project_root/module/src/test/java).

    Log files

    How to access the Diffblue Cover Plugin for IntelliJ log files, to better understand the tool's behavior and for debugging purposes.

    User logs

    Cover Plugin creates and maintains a user log file, user.log, in the following locations:

    Windows: %USERPROFILE%\AppData\Local\Temp\diffblue\log

    Linux: /tmp/diffblue/log

    Test insertion order

    The order of insertion of test methods by Cover Plugin for Intellij

    Created test methods are inserted into a test class in the same order that the methods under test appear in the source class (Diffblue Cover does not add a duplicate test if exactly the same test already exists).

    Source Class

    Test Class

    Troubleshooting

    Hints and tips for troubleshooting Cover Plugin for IntelliJ.

    This topic provides general troubleshooting information - please refer to the topic for more specific details.

    Structural issues with the project

    Please ensure that you are using Cover Plugin for IntelliJ on a complete project, as the plugin is unable to run successfully if there are flaws in the project structure. Check that:

    • All modules in the project are configured correctly.

    Cover Plugin toolbar menu

    The Cover Plugin toolbar menu provides many actions for the user:

    • Write tests & Write Skeleton tests. For more information see .

    • Change Settings. For more information see .

    • Clear Environment Check Cache. For more information see

    Cover CLI

    Diffblue Cover CLI automatically writes Java unit tests for your methods, classes, modules, and projects and provides access to the wider and deeper Diffblue Cover feature set. This set of topics provides all the details you need - for getting started information (installation, licensing, and test examples), see .

    eLearning

    Basics first - just in case you missed the getting started video.

    Beyond the basics - try out the overview video.

    Test insertion order

    The order of insertion of test methods by Cover Plugin for Intellij

    Created test methods are inserted into a test class in the same order that the methods under test appear in the source class (Diffblue Cover does not add a duplicate test if exactly the same test already exists).

    Source Class

    Test Class

    Test Formatting

    The format of tests produced by Cover Plugin for IntelliJ can be configured via the "Test Formatting Options" within settings.

    To configure the format of tests written by Cover Plugin, go to Diffblue > Change Settings > Test Formatting in IntelliJ.

    IntelliJ Code Style Formatting Compatibility

    It's important to note that the formatting of tests produced by Cover Plugin for IntelliJ, especially regarding indentation and other style settings, is in line with your current IntelliJ Code Style configurations. This ensures that the generated tests adhere to the code style settings you've set up in your IDE. If you experience formatting conflicts with other tools, such as Spotless, you might need to align your IntelliJ code style settings with those tools to maintain consistency.

    You are able to turn off IntelliJ Code Style formatting through the Diffblue settings menu "Apply code style formatting". With this setting turned off tests will be formatted in a way that will match the output of Cover CLI.

    Administrator

    Detailed learning paths targeted at "administrators" - manage and maintain Diffblue Cover for you, or your organization:

    Achievements:

    Memory management

    Tips for memory management, including how to increase the amount of memory that Diffblue Cover has access to.

    Minimum memory

    The amount of memory utilized by Diffblue Cover depends on the complexity of the project being analysed - complex projects will require more memory than simple projects. The minimum system requirements are 16GB RAM with 8GB allocated as heap for Java to use. By default Java allocates a quarter of the total RAM as heap, therefore this must be overridden where the amount of RAM is less than 32GB. Recommended system requirements for running Diffblue Cover alongside other memory-intensive applications include 32GB of RAM.

    Test formatting

    The format of tests produced by Cover Plugin for IntelliJ can be configured via the "Test Formatting Options" within settings.

    Use the --output-comments=<value> argument to select basic formatting options for tests written by Cover CLI (define the use of the // Arrange, // Act, and // Assert sections and comments).

    Usage: --output-comments=<value>

    Example: --output-comments=false

    Default: true

    Out of memory due to complex projects

    Not allocating enough heap to Java can result in out of memory errors - in these circumstances it is necessary to increase the memory available to Diffblue Cover above 8GB. As a rule of thumb, the memory requirements of Diffblue Cover are proportional to the memory requirements of the project being analysed.

    Cover Plugin - increasing memory

    Cover Plugin for IntelliJ requires access to a minimum of 4GB of memory to run effectively. If you do not have enough memory available, Diffblue Cover will automatically adjust the memory setting. You can undo this change (but please note that your IDE may be unstable without sufficient memory).

    If you wish to adjust the available memory manually, please go to Help > Change Memory Settings in IntelliJ and amend the Maximum Heap Size to at least 4096.

    This will update the memory allocation in your .vmoptions file. Please restart your IDE for these changes to take effect.

    Cover CLI - increasing Java heap

    The Java option -Xmx<max heap size> sets the maximum heap allocated to Java (more information about this option is available in the Java documentation; e.g. for Java 8 https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html.

    Diffblue Cover utilizes the environment variable JVM_ARGS to specify Java options to use when running Diffblue Cover. Adding the Java option -Xmx<max heap size> to the JVM_ARGS environment variable will ensure that Diffblue Cover is allocated a specific portion of system memory.

    CMD example to set maximum heap available to Diffblue Cover to 8GB:

    set JVM_ARGS=-Xmx8g

    PowerShell example to set maximum heap available to Diffblue Cover to 8GB:

    setx JVM_ARGS "-Xmx8g"

    Bash example to set maximum heap available to Diffblue Cover to 8GB:

    export JVM_ARGS=-Xmx8g
    When you're ready, click Restart IDE to complete the update.

    If you use the installer, run the .exe installer and follow the on-screen prompts.

  • If you use the archive file, extract the .zip file to your existing Cover CLI folder. Note that if you'd like to retain the previous release files, move these to a different folder first or create a new folder for the new version. Make sure to update the PATH or DCOVER environment variable configured during your original install, if needed.

  • When your done, restart your PC. Once complete, run dcover version to check the install and PATH configuration - if all is OK, Cover will display the current version.

  • Linux/macOS:

    1. Using the link provided by Diffblue, download the Diffblue Cover CLI .zip file.

    2. Unzip the Cover CLI zip file to an appropriate installation location using the following example commands. Note that if you'd like to retain the previous release files, move these to a different folder first or create a new folder for the new version. Make sure to update the PATH environment variable configured during your original install, if needed.\

      mkdir ~/bin
      cd ~/bin
      unzip ~/diffblue-cover*.zip
      export PATH=$PATH:~/bin

      Reminder: Make sure that the PATH environment variable is set permanently according to your operating system instructions.

    3. Once complete, run dcover version to check the install and PATH configuration - if all is OK, Cover will display the current version.

    Install and update Cover Reports
    Command summary
    Commands & Arguments
    Creating partial tests
  • The project is compilable.

  • The Java SDK version is correct for your project.


  • Test directories

    IntelliJ looks for an existing test source directory. If an existing test source directory cannot be found, it will create one and then notify the user where the tests have been created.


    Memory settings

    Diffblue Cover Plugin for IntelliJ requires 4GB of memory to run effectively. If you do not have enough memory available, Diffblue Cover will automatically adjust the memory setting. You can undo this change (but please note that your IDE may be unstable without sufficient memory).

    If you wish to adjust the available memory manually, please go to Help > Change Memory Settings in IntelliJ and amend the Maximum Heap Size to at least 4096.

    This will update the memory allocation in your .vmoptions file. Please restart your IDE for these changes to take effect.


    Error scenarios - inaccessible methods

    If you are receiving spurious warnings about inaccessible methods, close IntelliJ and delete the .diffblue index file. A new one is automatically created when Cover Plugin is run again.


    Error scenarios - inotify watchers

    In Linux, Diffblue Cover uses the inotify(7) filesystem API to watch for changes to your class files. If you are receiving an error message about running out of inotify watchers, please follow the advice below to increase the number of watch handles:

    1. Add the following line to either the file /etc/sysctl.conf or a new *.conf file under the /etc/sysctl.d/ directory: fs.inotify.max_user_watches = 524288

    2. Then run this command to apply the change: sudo sysctl -p --system

    3. Finally, restart your IDE. You should now have enough watch handles for IntelliJ to successfully create your tests.


    Resolving Formatting Conflicts between IntelliJ and Spotless

    Issue:

    Users may encounter formatting discrepancies when using Cover Plugin alongside other tools like Spotless. This can lead to unexpected changes in code formatting which may disrupt the development workflow.

    Cause:

    This issue typically arises when the formatting configurations in IntelliJ are not aligned with those specified by Spotless.

    Solution:

    To ensure consistent formatting and avoid any unexpected changes, we recommend that you align the formatting settings in IntelliJ with those of Spotless.

    Output Codes
    Minimal CI/CD System
    Slow CI/CD System
    Fast CI/CD System
    install Cover Reports
    Cover CLI
    Cover Plugin
    Telemetry
    install Cover Reports
    Cover CLI
    Cover Plugin
    Telemetry
    install Cover Reports
    Cover Pipeline
    Cover CLI
    Cover Plugin
    Telemetry
    install Cover Reports
    Cover Pipeline
    Cover CLI
    Cover Plugin
    Telemetry
    Reference Deployment 1: No CI/CD System Available
    Reference Deployment 2: Minimal CI/CD System
    Reference Deployment 3: Slow CI/CD System
    Reference Deployment 4: Fast CI/CD System
    Diffblue Menu Bar

    To activate your license, from a Windows PowerShell (Windows) or Terminal (macOS/Linux) enter the command dcover activate <license-key> - replace <license-key> with the license key provided in your welcome email or provided by your organization.

  • Entering multiple different license keys will overwrite the existing key.

  • You can check your license status by running the command dcover license

  • Offline license activation
    Online license activation
    Licensing
    Privacy Notice
    Online license activation
    Offline license activation
    pricing plans
    Cover Editions
    Diffblue License Management Portal
    Editions
    Structure Tool Window
    Run Configurations

    Get Started - Cover Plugin

    Automatically write unit tests for your methods and classes directly in your IDE.

    Get Started - Cover CLI

    Automatically write tests for your entire project using the CLI tool.

    Get Started - Cover Pipeline

    Integrate Diffblue Cover directly into your CI Pipeline.

    Get Started - Cover Reports

    Visualize and manage your test coverage.

    Free-Trial

    Get up and running with your trial version of Cover Plugin and Cover CLI.

    Update

    Update your Cover Plugin and Cover CLI installs to the latest version.

    Cover
    Cover
    Cover
    Cover
    Using SonarQube with Cover CLI
    .
    As illustrated above, the test methods testAbc and testXyz are not inserted alphabetically into the test class, but instead according to how the methods under test are ordered. Test methods which test the same method are inserted in the order in which they are generated by Cover Plugin.
    public class MyClass {
        public void xyz() {
        }
        public void abc() {
        }
    }
    public class MyClassDiffblueTest {
        public void testXyz() {
        }
        public void testAbc() {
        }
    }
    As illustrated above, the test methods testAbc and testXyz are not inserted alphabetically into the test class, but instead according to how the methods under test are ordered. Test methods which test the same method are inserted in the order in which they are generated by Cover CLI.
    public class MyClass {
        public void xyz() {
        }
        public void abc() {
        }
    }
    public class MyClassDiffblueTest {
        public void testXyz() {
        }
        public void testAbc() {
        }
    }
    type as an argument and behaves in different ways depending on that argument's value.

    Note in particular that the method exhibits the same behavior when the level argument is INFORMATIONAL or WARNING. Two tests that exercise this method by passing those two values to its first argument will therefore cover the same lines of code.

    When we write tests on this method with Cover all enum values disabled, then Cover Plugin creates these tests:

    When we enable Cover all enum values and write tests again, Cover Plugin creates these tests:

    With Cover all enum values enabled the Cover Plugin creates an extra test, to ensure that both the INFORMATION and WARNING levels are tested, even though the extra test may not increase the test suite's measured coverage.

    Disable "Cover all enum values"

    The Cover all enum values feature is enabled by default. To disable, go to Diffblue > Change Settings > Test Creation in IntelliJ, and uncheck the Allow writing tests for all enum values option.

    @Test
    public void testAsHtml() {
      assertEquals("<p style=\"color:orange\"><em>non-fatal: Not all who wander are lost</em></p>",
          (new ErrorFormatter()).asHtml(ErrorLevel.INFORMATIONAL, "Not all who wander are lost"));
      assertEquals("<p style=\"color:red\"><strong>FATAL! Not all who wander are lost</strong></p>",
          (new ErrorFormatter()).asHtml(ErrorLevel.FATAL, "Not all who wander are lost"));
    }
    Brief

    Using --output-comments=false, Cover CLI will create tests in a more condensed format - the // Arrange, // Act, and // Assert comments are removed and the sections are inlined:

    Standard

    Using --output-comments=true (or not specifying the argument at all), the Arrange, Act, and Assert sections will be labelled, but may still be combined together by inlining if they're small, for example:

      @Test
      public void testHasItem() {
        assertFalse((new Order()).hasItem());
      }
    @Test
    public void testHasItem() throws Exception {
      // Arrange and Act
      boolean actual = (new Order()).hasItem();
    
      // Assert
      assertEquals(false, actual);
    }
    public class ErrorFormatter {
    
      private static final String NON_FATAL_ERROR_TEMPLATE =
          "<p style=\"color:orange\"><em>non-fatal: %s</em></p>";
    
      private static final String FATAL_ERROR_TEMPLATE =
          "<p style=\"color:red\"><strong>FATAL! %s</strong></p>";
    
      public String asHtml(ErrorLevel level, String message) {
        switch (level) {
          case INFORMATIONAL:
          case WARNING:
            return String.format(NON_FATAL_ERROR_TEMPLATE, message);
          case FATAL:
            return String.format(FATAL_ERROR_TEMPLATE, message);
          default:
            throw new AssertionError(String.format("Unrecognised error level %s", level));
        }
      }
    }
    @Test
    public void testAsHtml() {
      assertEquals("<p style=\"color:orange\"><em>non-fatal: Not all who wander are lost</em></p>",
          (new ErrorFormatter()).asHtml(ErrorLevel.INFORMATIONAL, "Not all who wander are lost"));
      assertEquals("<p style=\"color:orange\"><em>non-fatal: Not all who wander are lost</em></p>",
          (new ErrorFormatter()).asHtml(ErrorLevel.WARNING, "Not all who wander are lost"));
      assertEquals("<p style=\"color:red\"><strong>FATAL! Not all who wander are lost</strong></p>",
          (new ErrorFormatter()).asHtml(ErrorLevel.FATAL, "Not all who wander are lost"));
    }
    Advanced users may prefer the Cover CLI tool.
  • More powerful, scriptable, and can generate tests for entire projects with a single command.

  • Works 100% autonomously, configuring itself from your Maven or Gradle environment.

  • Provides access to a wider feature set such as running preflight environment checks, creating coverage report bundles for use with Cover Reports, restricting test creation to code changes only, and more.

    • Integrate the power of Cover CLI into your CI pipeline.

    • Cover Pipeline creates and keeps your entire team's unit tests up-to-date within your GitHub, GitLab, Maven, Jenkins, Azure, AWS, or other CI pipelines.

    • Each time a pull request is opened Cover can automatically create, execute, and update your unit test library at appropriate points in the process.

    • The Cover Pipeline CI integration is the most scalable, reliable, repeatable option - unit testing becomes an effortless part of your workflow.

    Understand risk. Reports show you exactly what code isn’t tested, how important it is, and why tests might not have been written.

  • Benchmark and track the effectiveness of your Java unit testing over time.

  • Track how Diffblue Cover is being used across your organization.

    • Selective unit test execution, integrated into Cover CLI and Cover Pipeline.

    • Automatically selects only the unit tests required to fully validate that a code change hasn’t introduced regressions.

    • Reduce developer waiting time, reduced cloud computing costs, optimized PR workflows.

    • Automated code refactoring tool to improve testability and test coverage.

    • Integrated into Cover CLI and Cover Pipeline.

    • Cover Refactor can suggest and apply code refactorings that improve the observability of Java code and make it more testable.

    • Better code, increased coverage, reduced regression risk.

    Increase coverage. Get to 80% coverage in half the time! Diffblue Cover creates unit tests in bulk to help your team quickly assess the quality of your test suite.

  • Untangle legacy code. Our tests document your code, making scary code changes easy. This helps you to quickly write tests for large legacy codebases, and identifies untestable code that should be refactored.

  • Reduce development costs and increase productivity. With reduced or eliminated developer time, optimized test runs, CI/CD integration, and more, Diffblue Cover works 24/7.

  • Document your code. Diffblue Cover unit tests describe every behavior of every method - effectively documenting your code to make future code changes quicker and reduce regressions.

  • Monitor coverage and understand risk. Cover shows you exactly what code isn’t tested, how important it is, and why tests might not have been written. Target developer expertise more efficiently, either at areas of most risk or those where additional coverage can most easily be delivered.

  • Accelerate modernization and cloud migration. Diffblue Cover can support the migration from applications to microservices by providing a documented code base and improved test coverage.

  • Keep code private. Diffblue Cover’s generative AI operates entirely within your environment. No data ever leaves your organization.

  • (
    AmazonS3Exception
    e) {
    throw new IllegalStateException("Totally handled this exception", e);
    }
    }
    Autowired
    private AmazonService amazonService;
    /**
    * Method under test: {@link AmazonService#uploadFileToBucket(String, String, File)}
    */
    @Test
    void diffbluetestUploadFileToBucket() throws SdkClientException {
    // Arrange
    PutObjectResult putObjectResult = new PutObjectResult();
    putObjectResult.setContentMd5("MjdjN2NmNDAwMjI5MTAzZTAwYzZkODgzMDAyOWUyOWI=");
    when(amazonS3.putObject(Mockito.<String>any(), Mockito.<String>any(), Mockito.<File>any()))
    .thenReturn(putObjectResult);
    // Act and Assert
    assertSame(putObjectResult, amazonService.uploadFileToBucket("bucket-name", "object-key",
    Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile()));
    verify(amazonS3).putObject(Mockito.<String>any(), Mockito.<String>any(), Mockito.<File>any());
    }
    }

    The test does not have assertions.

  • The test does not always pass when executed.

  • The Arrange or Act sections produce an error when executed.

  • The test may execute code that is potentially harmful to your system, leaks resources or times out.

  • Creating such tests is useful to developers for two reasons:

    • Firstly, it will save developers time. Instead of writing tests from scratch, they'll be able to use the partial tests as a starting point.

    • Secondly, it may help developers understand why Diffblue Cover was not able to complete the test automatically, especially in cases where the reason for not producing a test is lack of testability.

    For example, for the method increment in the following class:

    Diffblue Cover will create a partial test:

    The problem is clearly that Diffblue Cover has no opportunity to assert on the side effect of the increment method on field x, which is marked private. The developer could add a getter to MyClass:

    Selecting or Write Tests again would now create a complete test.

    Disabling the creation of partial tests

    This feature is enabled by default. To disable the creation of partial tests, go to Diffblue > Change Settings > Partial Test Creation and uncheck the boxes for the relevant Allow writing tests ... options. This will disable the creation of partial tests unless no other tests could be created. If no other tests could be created when selecting or Write Tests then Diffblue Cover will create a skeleton test with simple inputs to get you started.

    We recommend always explicitly creating a test source directory src/test/java in the relevant module so that Cover Plugin knows where to put new test classes.

    Cover Plugin does not add a duplicate test if exactly the same test already exists.

    Override Test Directory

    If you have multiple test source directories set up for a module, you can use the Override Test Directory setting to ensure that Cover Plugin creates tests in your preferred directory - go to Diffblue > Change Settings and expand the Diffblue Cover settings menu on the left. Note that this is a project setting.

    For example, you may have a Gradle configuration similar to the following:

    Use the Override Test Directory setting to make sure that Cover Plugin adds tests to the src/diffblueTest/java directory:

    sourceSets {
        test {
            java {
                srcDir "src/test/java"
                srcDir "src/diffblueTest/java"
            }
        }
    }
    macOS: $TMPDIR/diffblue/log

    Support logs

    Cover Plugin also creates a support.log log file, in the same directory, which is only relevant to the Diffblue support team. If you raise a support issue then you may be asked to provide this log file.

    Accessing logs

    Cover Plugin provides simple access to logs via the Diffblue Cover tool window. After writing tests, simply look for the Open Logs button and select your desired action.

    • Open user log: Opens the diffblue user log - for this specific run - within IntelliJ IDEA.

    • Open support log: Opens the diffblue support log - for this specific run - within IntelliJ IDEA.

    • Open logs folder: Opens the folder containing all diffblue logs within Windows Explorer, Finder or equivalent.

    View and Activate License. For more information see Core Maintenance

  • View documentation. This will load docs.diffblue.com

  • Community Support Forum. This will load forum.diffblue.com

  • Submit Feedback. This will load a feedback form.

  • Getting Started. This will launch the Getting Started experience which will take you through the essentials of using the plugin.

  • What's New. This will load the latest release news and updates. See What's new.

  • Discover Diffblue Cover
    Cover Plugin settings
    Environment Check Cache

    Test Styles

    Select your preferred Test Style from the drop-down menu ( Brief, Standard, Verbose, or Custom). Selecting Brief, Standard, or Verbose will configure preset settings for the individual formatting options. The Custom style allows you to configure the options as you wish.

    Brief Test Style

    Using this style, Diffblue Cover will create tests in a more condensed format - the contents of the Arrange and Act sections are inlined into the Assert section, for example:

    Standard Test Style

    Using this style provides a compromise between the Brief and Verbose styles. The Arrange, Act, and Assert sections will be labelled, but may still be combined together by inlining if they're small, for example:

    Verbose Test Style

    Using this style, Cover Plugin creates tests containing up to three commented sections - Arrange, Act, and Assert. For example:

    Custom Test Style

    Selecting the Custom style allows you to configure the formatting options as you wish. Also note that changing any of the default options for Brief, Standard, or Verbose will automatically change the Test Style to Custom.

    Unit Tests - IDE

    Use Diffblue Cover within the IntelliJ IDE to create tests for your methods and classes.

    Unit Tests - CLI

    Use Diffblue Cover from a command line to create tests for your projects.

    Test Coverage

    Create coverage reports and improve test coverage.

    Developer

    Generate and upload Cover Reports bundles.

    Senior Developer

    Use Cover Reports to monitor and manage test coverage.

    Administrator

    Manage and maintain your Cover Reports instance.

    Just the basics

    Diffblue Cover basic concepts.

    Free trial

    Get started with the free trial (IDE and Command Line) and create tests for a sample project.

    Cover Plugin (IDE)

    A focus on the IntelliJ IDE. Get started with Cover Plugin and create tests for sample methods and classes directly in your IDE.

    Cover CLI (Command Line)

    A focus on the command line. Get started with Cover CLI and create tests for an entire sample project using the CLI tool.

    Get started - Cover CLI

    Write Tests

    Automatically write unit tests for your projects.

    Configure Your Projects

    Set up your projects to get the best tests from Diffblue Cover.

    Commands & Arguments

    Every command, every argument, every options - all the details you need.

    Admin

    Get your admin done, including telemetry config, log files, memory management, etc.

    Cover Reports Intro

    [2 min read]

    A brief introduction to Cover Reports.

    Dashboards

    [5 min read]

    Coverage data and visualizations available through each of the dashboards/tabs.

    Telemetry

    [3 min read]

    Monitor Diffblue Cover usage across your organization.

    Considerations

    [3 min read]

    A few considerations for managing your coverage data and Cover Reports deployment.

    Admin - IntelliJ

    Install, manage, and maintain Cover Plugin.

    Admin - CLI

    Install, manage, and maintain Cover CLI.

    Admin - Reports

    Install, manage, and maintain Cover Reports.

    Cover CLI (Command Line)

    Trying out Diffblue Cover for the first time? Get up and running with the trial version of Cover CLI and start writing unit tests for your projects from the command line.

    Interested in integrating Diffblue Cover into your CI/CD pipeline? Jump over to the DevOps Learning Paths.

    Start here...

    Alternatives...

    Next steps...

    Now you've got the basics, move on to the core learning paths for Cover CLI:

    FAQs

    The things we get asked the most. Always worth a look.

    What is Diffblue Cover?

    Diffblue Cover is a reinforcement learning AI platform that automatically writes comprehensive, human-like Java unit tests. Cover is provided as an IDE plugin (Cover Plugin) and a CLI application (Cover CLI) for developer use and can also be integrated into your CI Pipeline (Cover Pipeline). We've also added three reporting and optimization tools for further monitoring and management control (Cover Reports, Cover Optimize, and Cover Refactor).

    See What is Diffblue Cover? for more details and to view our intro video.

    Do I have to upload my code to a cloud service?

    No. Cover Plugin and Cover CLI are used on developer workstations and Cover Pipeline operates within your CI environment.

    What are the benefits of using Diffblue Cover?

    Diffblue Cover helps your team increase automation of your CI pipeline.

    For development teams, this:

    • Improves velocity and quality of the software you deliver.

    • Frees up time to focus on creating new features.

    Will the tests find regressions in my code?

    Yes. Diffblue Cover quickly generates tests that will allow you to adopt CI. The generated tests will help developers quickly identify regressions in subsequent commits before committing new versions.

    What are the requirements for running Diffblue Cover?

    Basic pre-requisites:

    • Java 8, 11, 17, or 21 compatible source code, or Kotlin source code.

    • Maven 3.2.5+, Gradle 4.9+, or Ant 1.10.14+ build tools.

    How can I learn more about customers using Diffblue Cover?

    See our on how Goldman Sachs has benefited from using Diffblue Cover to increase coverage and create a safety net against regressions.

    For examples of other ways our customers use Diffblue Cover, .

    How do we maintain Diffblue unit tests in the future?

    Diffblue regression suites are maintained automatically and updated with each new code version to capture the current behavior of the code.

    How does Diffblue Cover help me adopt Continuous Integration?

    Diffblue Cover AI analyzes your code and writes Java unit tests that run in a CI pipeline after each commit. Cover’s tests:

    • Always compile.

    • Run quickly.

    Should our team stop writing unit tests after adopting Diffblue Cover?

    No. Diffblue Cover is meant to complement your own unit tests and help you catch regressions.

    How is a unit test different from a Diffblue regression suite?

    Developers write individual unit tests to test specific functionality. Diffblue regression suites are generated automatically to help find regressions early in the development cycle. Find out more in our .

    Cover Plugin

    How to use Diffblue Cover Plugin for IntelliJ to write Java unit tests

    Diffblue Cover Plugin automatically writes Java unit tests for your classes and methods directly within the IntelliJ IDE. This set of topics provides all the details you need - for getting started information (installation, licensing, and test examples), see Get started - Cover Plugin.

    eLearning

    Just in case you missed our getting started video.

    SonarQube Warnings

    How to address SonarQube warnings related to Diffblue Cover

    There are various SonarQube warnings that may be issues for tests created by Diffblue Cover. This page lists common warnings and how to address them, if they can be addressed. Note that there are specific ways to address SonarQube warnings in the Diffblue Cover Plugin and Diffblue Cover CLI. This page is for an overview of the warnings you may see and how they can be addressed with any version of Diffblue Cover.

    Configurable Warnings

    Refactor this method to reduce the number of assertions from X to less than N

    CLI only: Use the --max-assertions-per-test=(N-1) option to limit the number of assertions per test.

    Add at least one assertion to this test

    There are two common causes for this warning.

    1. An option has been given to Diffblue Cover to keep partial tests (docs for or ) or . In this case, tests without assertions are expected and the tests should be completed manually.

    2. This is due to SonarQube failing to recognize certain assertion methods. Most likely, you have to do the following:

      Add org.springframework.test.web.servlet.ResultActions#andExpect to the customAssertionMethods parameter for rule S2699. This explicitly tells SonarQube to treat andExpect as an assertion.

    Test method naming conventions

    By default, Diffblue Cover’s test method naming complies with the pattern [a-z][a-zA-Z0-9_]* You can change the method naming template if you want to create test names without underscores, for example. See method name template for or .

    Unresolvable Warnings

    Note that these warnings are where SonarQube and Diffblue Cover have different beliefs about what is best. These cannot be easily adjusted in Diffblue Cover, so the best approach is to suppress these or use other approaches as described for the and .

    Change the assertion arguments to not compare dissimilar types

    SonarQube may incorrectly flag this situation when testing that the equals method of a class returns false when called with differing types.

    Swap these two arguments so they are in correct order: expected value, actual value

    This is not expected to happen. If you see this file a support request with a concrete example of test code generated by Cover.

    Replace these N tests with a parameterized test

    Diffblue Cover currently does not support parameterized tests. This feature is on the roadmap. Stay tuned.

    Long variables

    Diffblue Cover prefers long, descriptive variable names which may have up to about 40 characters.

    Local variable could be final

    Local variables in tests generated by Diffblue Cover are never reassigned by construction. Diffblue Cover does not mark them using the final keyword.

    Unit test assertions should include message

    Diffblue Cover does not generate such messages as they unnecessarily increase the verbosity and thus reduce the readability of the tests.

    Comment required for field

    Diffblue Cover does not add JavaDoc comments to field declarations in test classes as they unnecessarily increase the verbosity and thus reduce the readability of the tests.

    Test Review

    Test Review allows you to edit, analyse and manage each of the tests Diffblue Cover creates for you, as soon as those tests are available.

    When enabled, you are given the opportunity to review and change the tests before they get added to your codebase.

    Beginning a review

    To perform a review, simply write tests as normal. The number of tests available for review is shown in the tool panel. Once the first test is created the Review Now button will become active; clicking this will take you to the first test waiting to be reviewed.

    Reviewing a test

    To help you review your tests, we display them inside a . When comparing side-by-side, on the left you'll see your original test file (the file your tests will be inserted into). On the right, you'll see Diffblue Cover's test suggestion. This includes the test that has been created, as well as any other modifications to the test class required for the test to run.

    You can use any of the features of the Diff Viewer to help you review your test, you can even edit the test inside the Diff Viewer if you wish.

    You must accept any test that you wish to edit in the Diff Viewer. All changes made will be lost when you navigate away from the test.

    Accepting a test

    Once you're happy with the test suggestion, you must accept it for the test to be added to your test file. If you have edited the test, these changes will be included when you accept.

    Any tests that are not accepted will be lost and can only be recreated by running Diffblue Cover again on the method under test. Please make sure you accept any test you want to keep.

    Accepting all tests

    You might wish to inspect each test, and accept them all in one action. In which case, when you are happy with your tests, you can use the dropdown menu of the accept button and click "Accept all".

    Rejecting a test

    If you do not wish to keep a test suggestion, for whatever reason, you can reject it. All tests can be rejected in one click using the "Reject all" option within the dropdown menu of the reject button.

    Once a test is rejected, it is lost. Rejected tests can only be recreated by running Diffblue Cover again on the method under test.

    Navigating through tests

    Once you have accepted or rejected a test, you will be automatically taken to the next test requiring your review.

    However, If you wish to inspect multiple tests before taking an action, or you wish to review a specific test, you can navigate through the tests to find what you want. The tree on the left displays all methods under test. If a method has any test requiring review, it will display a icon. Once all tests for the method have been reviewed, this icon will be replaced according to the status of the tests.

    There may be situations where Diffblue Cover creates multiple tests for a single method. In this case, a list of test methods will appear on the left. You can click through the items in this list to review the tests you're most interested in. This list can be resized or collapsed at any point while it is open.

    Alternatively, you can navigate through these tests with the left/right arrow icons below the Diff Viewer.

    Enabling/Disabling Test Review

    From Diffblue Cover IntelliJ Plugin 2025.03.01, Test Review is enabled by default - but it can be turned on or off at any time. When Test Review is disabled, tests will automatically be accepted and merged into your codebase.

    To enable or disable Test Review, follow these steps:

    1. Open the Diffblue Settings menu via Diffblue -> Change Settings

    2. Find the section titled "Test Review".

    3. Check or uncheck the Test Review checkbox.

    Cover Plugin tool window

    Diffblue Cover tool window in Cover Plugin

    When writing tests, the Cover Plugin tool window is displayed. The Overview panel provides summary progress and status information for each stage when writing tests - click an item to review detailed status and results in the Details panel, including preflight and environment check results, a Diff Viewer for reviewing tests written, test links, output codes, and general information.

    Preparing

    During this stage, Cover Plugin runs initial checks to ensure it can write tests. If there are any issues, the Overview panel will tell you which check failed, along with an explaination to help you resolve it. Example issues may include problems with licensing or compiling the project.

    Checking environment

    Next, Cover Plugin will check your project's environment, to make sure it is set up correctly. This checks your project and its dependencies against Diffblue . If Cover Plugin detects something outside of these requirements you may see warnings or errors in the Details panel - these can be expanded to display more information to help you resolve the issue and some may have automatic fixes (see below).

    Fix issues

    Certain errors and warnings reported during the Checking environment stage may have automated fixes available - click the Fix Issue button in the Details panel and Cover will attempt to automatically apply the fix to your project.

    Writing tests

    Finally, Cover Plugin will write your tests. The Overview panel displays the progress for each method (grouped by class) - select an item to review created tests, as well as to view details such as test links and general information for your tests once they have been reviewed.

    Cancel tests

    If you need to cancel test creation at any point, click the red Stop button.

    When you click Stop, any remaining methods will be marked as cancelled and tests will not be created for them. Any tests that have already been written will be retained for review and can be merged into your codebase once accepted.

    Note that cancelling test creation may not happen immediately. Cover will attempt to stop gracefully, so you may have to wait for its current progress to complete before the process is halted.

    Restart test generation

    Once test generation has finished, you can click on the restart button to rerun the test generation process.

    When you click Restart, the tool window will be cleared and Cover will attempt to write tests on the exact same configuration of methods or classes.

    Open logs

    Please see for more information.

    Open Support request

    If you need to raise a support request, click the Open support request button (not available for all users, please see for more details).

    Creating skeleton tests

    What are skeleton tests, how to get them and how can they help when using Diffblue Cover?

    Skeleton tests simply consist of a call to the method under test, with all variables initialized to null or zero, and some comments reminding the user to better populate the "arrange" section and come up with some assertions. They are intended as a helpful starting point for users to write their own tests.

    There are two ways of obtaining a skeleton test for a method in Diffblue Cover:

    • Click or select Write Tests - Diffblue Cover will analyze the method and related classes to write one or more complete tests (or partial tests if this is enabled) exploring the coverage that can be accessed from each method under test. Sometimes this approach is unsuccessful and rather than give you nothing, Diffblue Cover falls back to offering a single skeleton test for the method instead. In this case, the skeleton test provided is disabled, just like any other partial test that is not expected to pass.

    • Right-click and select Write Skeleton Tests - Diffblue Cover won't analyze your code to write complete tests but instead will only create a single skeleton test for the method. In this case, the skeleton test provided is not disabled as it's assumed that you will complete the test by hand immediately. This can be useful when you need to write a test reproducing a specific scenario and just want some help getting started.

    Skeleton tests are intentionally written with all available comments to aid readability, and minimal inlining to ease editing, which means that all test formatting options will be superseded.

    For example, consider the method in the following inner class in an outer class, DatabaseDao:

    Diffblue Cover is unable to test this by default as there doesn't appear to be a way of creating an instance of Inner on which to call myMethod(Inner), and so this results in an output code with some explanation why a full test could not be written. Rather than provide just the output code, Diffblue Cover will offer a skeleton test for the method as follows:

    This skeleton test serves as a helpful illustration of the output code, allowing you to play with your code and better understand why testing the method is difficult, and what could be changed to make it easier. In other cases you will know a way of obtaining an instance to test with, in which case you are well placed to complete the test by hand, choosing useful values for the variables and adding relevant assertions. Alternatively, you may want to "teach" Diffblue Cover how to create useful instances via .

    Test Coverage Optimizations

    Diffblue Cover can create many tests for a given package, class or even method, but how does Cover optimize the tests that it provides? And what options are there to help make sure that Diffblue Cover provides you the test coverage levels that you prefer?


    Test Class Coverage Optimization (Default)

    By default, Diffblue Cover will optimize test output by only providing tests which increase coverage within the target test class.

    What does Test Class Coverage Optimization look like?

    • For a source class Foo

    • Cover will create a test class called FooDiffblueTest

    • Cover will start to create test methods that exercise the contents of Foo and insert them into FooDiffblueTest

    • When a new test candidate is found by Cover, and its coverage does not increase upon the coverage in FooDiffblueTest, then it will be discarded.

    Through this methodology, Cover will aim to provide the minimum number of test methods to deliver the maximum coverage, in the test class.

    What does Test Class Coverage Optimization not do?

    • It does not consider coverage provided by test classes outside of the target test class.

    • It does not guarantee that each test provides unique coverage, in fact it is highly likely that there will still be coverage overlap between test methods within the same test class, just as there would be with manual testing. However each test will provide some unique coverage, within the test class.

    Disabling Test Class Coverage Optimization (ignore existing coverage)

    Disabling test class coverage optimization will allow Diffblue Cover to provide the maximum number of tests, including tests which provide duplicated coverage. This may increase test strength and mutation coveage.

    This can be achieved in the CLI and Plugin through use of the --ignore-existing-coverage options. See CLI: Plugin:

    Currently Test class coverage optimisation only support the JUnit Jupiter platform. For JUnit 4 / TestNG environments test class coverage optimisation will not be applied.


    Test Suite Coverage Optimization (new jacoco coverage)

    Optionally, Cover can optimize coverage across the entire test suite using the CLI option --new-jacoco-coverage. This will take into account the coverage provided by existing tests before starting to create Diffblue Tests. Tests created by Diffblue Cover are added if they increase JaCoCo coverage.

    Notable effects:

    • This has the ability to greatly reduce the number of DiffblueTests produced by Diffblue Cover, depending on existing test coverage levels.

    • This feature will reduce the overlap between Diffblue and Manual test cases, however not all overlap will be eliminated, while maintaining the same overall Coverage levels.

    • This feature may cause many Diffblue tests to be discarded that may be better quality than existing tests, or test other values or edge cases. This will likely reduce the overall strength and mutation coveage provided of the test suite.

    • If used in conjunction with

    For more information see

    The --new-jacoco-coverage option can be valuable for high quality, trusted, test suites, allowing Diffblue Cover to focus on adding new coverage to round out the test suite without adding code bloat.

    However, if you are looking to modernise your test suite, code or are at all unsure of the veracity of your test suite, then we would encourage you to take advantage of Covers ability to generate high quality, high strength tests, at scale, by NOT using this option. Once you have your Cover augmented test suite, consider the coverage and test strength improvements Cover has provided and balance that against any coverage or test duplication, you may find that deleting flakey or poorly understood manual tests is the correct approach for you.

    Gutter icons

    Cover Plugin for IntelliJ gutter icons

    Cover Plugin provides several icons in the "gutter" area next to methods and classes in the IntelliJ editor panel - click the icon displayed to write, update, or delete tests.

    Action icons

    Icon
    Description

    Displayed next to testable methods or classes in project files. Click the icon to write tests for the method or class.

    Status icons

    Icon
    Description

    Disable the icons

    To disable the icons in IntelliJ:

    1. Go to File -> Settings.

    2. Select Editor -> General -> Gutter Icons.

    3. In the Diffblue Cover section, uncheck the boxes corresponding to the icons you want to disable.

    Cover Plugin status bar widget

    The Cover Plugin status bar widget provides a quick view to see your current usage, as well as easy access to:

    • View License Info (to see more details about your license)

    • Activate License (to activate a new license - including upgrading to a new license)

    • Upgrade license (to find out more about license plans and purchase an upgraded license)

    Test coverage

    Create coverage reports and improve test coverage. This learning path is targeted at developers - see the Test Coverage group for all coverage related learning paths.

    Before starting this learning path, we recommend that you first complete the Cover CLI Get Started path or the Cover Plugin Get Started path.

    General dependencies

    Dependencies required for running tests should be in the project configuration. Additional libraries may also be necessary depending on the project under test. For version information, see Specs & Reqs.

    Dependency
    Description

    Test Framework

    See .

    Surefire Plugin org.apache.maven.plugins: maven-surefire-plugin

    When using Maven and junit-jupiter-engine.

    JUnit Launcher org.junit.platform: junit-platform-launcher)

    When using junit-jupiter-engine, unless using Maven, Spring, or Spring Boot.

    Spring Boot Test

    org.springframework: spring-boot-test

    When using Spring Boot ( org.springframework:spring-boot).

    Other dependencies listed below may be needed, if they are transitive dependencies of your project. If one of these dependencies is required but missing, tests will be generated for some classes but not others. A message will appear in the console output indicating a missing dependency. For version information, see .

    Dependency

    Command summary

    Command summary

    Command
    Description

    dcover create

    Create Tests - write tests for a project, package, method or class. See .

    dcover create --preflight

    Run Preflight Checks - verifies whether the local environment and the project are in the best condition possible for dcover to create tests, without actually creating the tests. See for full details.

    Create tests

    Usage: dcover create [@<argumentFile>...] [<entryPoint>...] [--<argument>...]

    Example: dcover create @argfile.txt io.corebanking.Account --maven

    Inline help: dcover help create

    Description: The dcover create command writes tests for your projects, packages, classes, and methods.

    • By default, dcover create automatically writes tests for the entire project. If required, you can specify what packages, classes, or methods you want to write tests for, on the command line (using [<entryPoint>...]) - see .

    • You can use one or more optional arguments on the command line to specify additional Diffblue Cover options such as running preflight checks, excluding methods, or uploading reports bundles (using [--<argument>...]) - see the topic.

    • Command lines can become very long when multiple options are specified. To keep your command lines short and avoid any potential issues with terminals that don't support very long command lines, you can make use of argument files to define your optional arguments (using

    Output Codes

    Cover CLI performs a number of checks before, during, and after creating unit tests. Cover can generate a range of output codes during these checks to provide general information and highlight any issues. Details for all output codes are provided in the main topic. Note that as and when these output codes are displayed within Cover CLI, additional specifics may also be provided, if relevant. Also, some common issues can be resolved automatically using dcover refactor - see .

    Cover Plugin admin

    Common Cover Plugin admin:

    • Telemetry Config: Enable/disable and configure telemetry for Cover Plugin.

    • Memory Management: Tips for memory management, including how to increase the amount of memory that Diffblue Cover has access to.

    • SonarQube: Suppress warnings and reduce reported "code smells" in SonarQube.

    • : User and Support Log Files.

    • : Help with a few common issues that you may encounter.

    Test naming

    Instructions on how to define the naming system used for tests generated by the Cover Plugin for IntelliJ.

    By default, test classes created by Diffblue Cover are named <CLASS_NAME>DiffblueTest and test methods are named test<INNER_CLASS_NAME><UNIT_NAME>. To change the naming, use the class-name-template and method-name-template options as detailed below.

    Class name template

    The --class-name-template="${CLASS_NAME}<string>" argument can be used to define the test class naming convention for tests written by Diffblue Cover. The ${CLASS_NAME} variable will be substituted with the name of the class under test.

    Usage: --class-name-template="${CLASS_NAME}<string>"

    Example: --class-name-template="${CLASS_NAME}CreatedTest"

    Default: ${CLASS_NAME}DiffblueTest

    Usage: --class-name-template=\${CLASS_NAME}<string>

    Example: --class-name-template=\${CLASS_NAME}CreatedTest

    Default:

    Method name template

    The --method-name-template="<string><variable>[<variable>...]" argument can be used to define the test method naming convention for tests written by Diffblue Cover. Available variables are as follows:

    • The ${INNER_CLASS_NAME} variable will be substituted with the name of the inner class for the method under test. If there's no inner class this will be an empty string.

    • The ${UNIT_NAME} variable will usually be substituted with the name of the method under test. Where the unit under test comprises multiple methods (getters and setters, equals and hash code) the more general unit under test name is used.

    • The ${METHOD_NAME} variable will be substituted with the name of the first method under test, typically the only method under test.

    Usage: --method-name-template="<string><variable>[<variable>...]"

    Example: --method-name-template="aitest${INNER_CLASS_NAME}${METHOD_NAME}"

    Default: test${INNER_CLASS_NAME}${UNIT_NAME}${_}${GIVEN}${_}${WHEN}${_}${THEN}

    For example, using the default naming convention for an inner class Foo with an equals(Object) and hashCode() implementation, a test method might be named testFooEqualsAndHashCode_whenOtherIsEqual_thenReturnEqual.

    Disambiguation

    Disambiguation between tests of the same name is performed automatically using sequential numbering:

    Other CI

    Integrate Cover CLI into your CI pipeline workflow - Jenkins, Azure, AWS.

    Start here...

    Alternatives...

    Offline license activation

    How to activate your Diffblue Cover license offline

    Licensing Diffblue Cover in the offline mode detailed here is available only when purchased with the offline option. To use Diffblue Cover in an offline environment, such as a high-security or air-gapped network, requires this offline option.

    Otherwise Diffblue Cover requires a with the Diffblue licensing server each time it is used.

    Activating an offline license

    This section describes how to activate a Diffblue Cover offline license.

    Module 6: Getting more from Cover

    We will delve into advanced features of Cover that will allow you to write more tests and improve the testability of your codebase.

    To start this module you must have completed or .

    For each group of methods that Cover analyzes, it either creates tests or it outputs a code that explains why it was not able to write a test. These output codes are the starting point for making Cover write more tests. ->

    In many cases Cover can output a that shows how far Cover got with writing a test. The partial test allows you to better understand the output code in the context of your code. By debugging such a partial test, you can gather more information to identify what is required to make Cover write more tests. -> Methodology for

    Admin - IntelliJ

    Manage and maintain Cover Plugin for yourself or your organization.

    Before starting this learning path, we recommend that you first complete the path and (optionally) the path.

    Start here...

    Admin - Reports

    Manage and maintain your Cover Reports instance.

    Start here...

    Next steps...

    Get started - Cover Reports

    Get started with Diffblue Cover Reports - in short, check the prerequisites, download and install Cover Reports, create and upload a reports bundle, and finally, visualize your coverage data.

    Cover Reports is a server-side tool accessed via a web browser - Chrome, Edge, Safari, or Firefox. Cover CLI and/or Cover Pipeline are used to create and upload coverage data - Cover Reports is used to visualize that data. This getting started topic focuses on Cover CLI - for information on using Cover Reports with Cover Pipeline see .

    This topic covers Docker install only. As an alternative, Cover Reports can be installed from a zip archive or exe installer. These provide for running Cover Reports as a Windows Service, Linux Service, Windows .bat, or macOS/Linux .sh, and removes the need to use Docker. These also provide various database configuration options to provide further flexibility. See for details.

    Cover Plugin (IDE)

    Trying out Diffblue Cover for the first time? Get up and running with the trial version of Cover Plugin for IntelliJ and start writing unit tests for your methods and classes directly in your IDE.

    Start here...

    Prerequisites for onboarding

    We recommend to start onboarding with a handful of selected projects from different teams. A project is typically an application or a repository.

    The onboarding of each selected project will be driven by a named champion. A champion is responsible for making the project ready for Diffblue Cover, creating the baseline and communicating with DevOps to set up Cover in CI. This is usually a team lead or a senior engineer on a team. They may already have been involved in an earlier proof-of-concept.

    To facilitate communication among yourselves and with Diffblue, you should gather the following information.

    1. Projects, teams and developers.

    Cover Reports Administrator

    Manage and maintain your Cover Reports instance.

    Start here...

    Next steps...

    Cover Plugin settings

    To modify the Diffblue Cover settings in IntelliJ, go to Diffblue > Change Settings and update as needed.

    • Test Framework: Select the test framework used for your project - JUnit 4, JUnit 5, TestNG, or Auto-Detect.

    Admin - CLI

    Manage and maintain Cover CLI for yourself or your organization.

    Before starting this learning path, we recommend that you first complete the path and (optionally) the path.

    Start here...

    Test framework dependencies

    Tests created by Diffblue Cover make use of a testing framework, namely one of JUnit 4, JUnit Jupiter, or TestNG - these frameworks are included in the required dependencies below. These dependencies are available from the Maven Central Repository. To add it, follow the guide relevant to your build tool.

    Maven

    Check whether or not the test framework dependencies are already in your Gradle project. If not, follow the instructions below to add it:

    1. Edit the build script (build.gradle

    Patch files

    How to create and use patch files for Cover CLI

    Use the --patch-only=<patch-file> argument to define a patch file - Diffblue Cover will only write tests for the code changes defined in the patch file (any class in the patch and any related/dependent classes).

    Command line argument

    Usage: --patch-only=<patch-file>

    Alternative: -p=<patch-file>

    Diffblue License Manager

    Guide on how to log in and use the Diffblue license manager

    Logging in

    The Diffblue license manager is for managing your organization's licenses. A license manager is assigned to each organization.

    Log in to using the username and password provided in your Diffblue welcome email.

    Creating partial tests

    By default, creation of partial tests is enabled in the Diffblue Cover Plugin for IntelliJ. This page covers partial tests and their uses, and how to turn off this option.

    About partial tests

    Normally, dcover create will create complete tests for a method. A complete test consists of Arrange, Act, and Assert sections and passes when executed. However, sometimes Diffblue Cover is not (yet) able to write complete tests and will give the reason for not creating complete tests in the output summary. In these cases, you can opt to retrain the partial tests created by Cover using the --keep-partial-tests option. Partial tests may be incomplete in various aspects:

    Developer

    Create coverage reports and improve test coverage. This learning path is targeted at developers - see the learning path for details of coverage monitoring and maintenance.

    Before starting this learning path, we recommend that you first complete the path and the path.

    Core Maintenance

    Install, Update, Disable, Re-Enable, and Uninstall Cover Plugin

    Install

    1. Install Diffblue Cover Plugin for IntelliJ

    public class MyClass {
        private int x;
        public void increment() {
    	  ++x;
        }
    }
      @Test
      public void testIncrement() {
        // TODO: This test is incomplete.
        //   Reason: R002 Missing observers.
        //   Diffblue Cover was unable to create an assertion.
        //   Add getters for the following fields or make them package-private:
        //     MyClass.x
    
        // Arrange
        MyClass m = new MyClass();
    
        // Act
       m.increment();
      }
    public class MyClass {
        private int x;
        public void increment() {
    	  ++x;
        }
    	public int getX() {
    	  return x;
    	}
    }
      @Test
      public void testHasItem() {
        assertFalse((new Order()).hasItem());
      }
    @Test
    public void testHasItem() throws Exception {
      // Arrange and Act
      boolean actual = (new Order()).hasItem();
    
      // Assert
      assertEquals(false, actual);
    }
    @Test
    public void testHasItem() throws Exception {
      // Arrange
      Order order = new Order();
    
      // Act
      boolean actual = order.hasItem();
      boolean resultBoolean = false;
    
      // Assert
      assertEquals(resultBoolean, actual);
    }
    For DevOps teams, this:
    • Helps catch errors and issues earlier (shift left!).

    • Improves deployment frequency, lead time, and mean time to repair (MTTR).

    See Diffblue Cover What is Diffblue Cover? for more details.

    The project (for use with Diffblue Cover) must compile and run with no failing unit tests. JUnit and TestNG testing frameworks are supported.

    More details:

    Diffblue Cover requires that the system environment (hardware, operating system, network connectivity, Java installation) as well as the project environment (build tooling, dependencies, presence of artifacts, existing unit tests) meet the minimum requirements as detailed in Specs & Reqs. Diffblue Cover will perform an environment check before analysis begins to ensure that the requirements are met - if there are any issues, these will be reported using Output Codes.

    Note that you can run dcover create --preflight (using Diffblue Cover CLI) to check the Cover pre-requisites for your project, without performing any other actions.

    Detect regressions from previous versions.

  • Improve coverage.

  • Are easy to understand.

  • case study
    click here
    Unit Regression Tests eBook
    plugin
    CLI
    skeleton tests
    plugin
    CLI
    Diffblue Cover Plugin
    Diffblue Cover CLI
    --ignore-existing-coverage
    then Diffblue Cover may still provide redundant coverage within its own test classes.
    Commands & Arguments
    Cover Plugin settings
    Commands & Arguments
    Log Files
    Troubleshooting

    Spring Test org.springframework: spring-test

    When using Spring ( org.springframework:spring-core) unless using Spring Boot.

    Mockitoorg.mockito: mockito-core

    For mocking using Mockito.

    Java Servlet API

    javax.servlet:javax.servlet-api or jakarta.servlet:jakarta.servlet-api

    JSR107 API and SPI

    javax.cache:cache-api

    Spring Boot Starter Test

    org.springframework.boot:spring-boot-starter-test

    Spring Security Config

    org.springframework.security:spring-security-config

    Spring Web MVC

    org.springframework:spring-webmvc

    Specs & Reqs
    Test framework dependencies
    Test Creation:
    • Enable/disable the use of Cover all enum values (ensure all enum values are covered, when an enum is used as a method argument or return value) - see Covering all enum values.

    • Enable/disable the use of Ignore existing coverage (default: off) - see Test Coverage Optimizations

  • Partial Test Creation: Enable/disable the creation of partial tests for specific scenarios - see Creating partial tests.

  • Test Review: Enable manual review and editing of tests before they are added to your codebase - see Test Review

  • Test Naming: Define the test class and test method naming conventions used for tests written by Diffblue Cover - see Test Naming.

  • Test Formatting: Select the test style or specific formatting options for tests written by Diffblue Cover - see Test Formatting.

  • Spring: Set your Spring configuration options (mocking, Spring contexts, and active profiles) - see Spring configuration options.

  • Method Annotations: Suppress compiler warnings for test methods written by Diffblue Cover - see Method Annotations. This is especially useful when using SonarQube - see Using SonarQube with Cover Plugin.

  • Sandboxed Environment: Enable (default) or disable the Diffblue Sandbox and/or define a list of allowed JNI libraries (if needed) - see Diffblue Sandbox.

  • In addition to these settings, the host environment can be configured in several ways which are described in Environment Configuration

    Apply the settings.
    Diff Viewer
    specifications and requirements
    accessing logs
    Cover Editions
    Fix issues
    or
    build.gradle.kts
    ).
  • Add Maven to the repositories section.

  • Add JUnit or TestNG to the dependencies section:

  • For JUnit 4:

     dependencies {
         testCompile group: 'junit', name: 'junit', version: '4.13.2'
     }
     dependencies {
         testCompile("junit:junit:4.13.2")
     }

    For JUnit Jupiter 5:

     dependencies {
         testCompile group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.8.0'
     }
     dependencies {
         testCompile("org.junit.jupiter:junit-jupiter:5.8.0")
     }

    For TestNG:

    Gradle

    Check whether or not the test framework dependencies are already in your Gradle project. If not, follow the instructions below to add it:

    1. Edit the build script (build.gradle or build.gradle.kts).

    2. Add Maven to the repositories section.

    3. Add JUnit or TestNG to the dependencies section:

    For JUnit 4:

    For JUnit Jupiter 5:

    For TestNG:

    Run the tests

    Choose one of the new test classes in the project explorer, right-click and select 'Run ClassnameTest'. The IDE will then show the results of the run.

    R008
    Custom Inputs
    ${CLASS_NAME}DiffblueTest

    The ${GIVEN} variable will be substituted with a summary of the conditions prior to the method(s) under test being called, or a blank string if no description is available.

  • The ${WHEN} variable will be substituted with a summary of the conditions when the method(s) under test are called, or a blank string if no description is available.

  • The ${THEN} variable will be substituted with a summary of the consequences the method(s) under test being called, or a blank string if no description is available.

  • The ${_} variable will be substituted with a _ separator, or a blank string if there are no values to separate.

  • To avoid duplication, do not use ${UNIT_NAME} and ${METHOD_NAME} together.

  • Usage: --method-name-template=<string><variable>[<variable>...]

    Example: --method-name-template=testCreated\${INNER_CLASS_NAME}\${METHOD_NAME}

    Default: test${INNER_CLASS_NAME}${UNIT_NAME}${_}${GIVEN}${_}${WHEN}${_}${THEN}

    For example, using the default naming convention for an inner class Foo with an equals(Object) and hashCode() implementation, a test method might be named testFooEqualsAndHashCode_whenOtherIsEqual_thenReturnEqual.

    Example: --patch-only=path/to/file.patch
    • Use diff or a similar tool to create a patch file for your changes in your project - for example: git diff origin/develop > file.patch.

    • For a multi-module project, generate the patch at the root of the project and provide the absolute path to the patch file, using --working-directory with the relative path to the module. The same patch file can be used for each module.

    • For a project without modules, or a project where tests will only ever be created for a single module, where --working-directory is not used, the relative path to the patch file for the project or module only may be used - for example:

    • The --patch-only argument only accepts files in UTF-8 encoding. If using PowerShell on Windows, use the following command to get the patch in UTF-8 instead of the default UTF-16:

    Create a patch file

    The exact patch file you need depends on your setup, but here are some examples using git diff. The variable DIFFBLUE_PATCH represents the name of your patch file.


    For a patch containing commits newer than the project's origin (i.e. the corresponding branch on the remote repository your local branch was created from):


    For a patch containing commits on your branch newer than those on the local copy of TARGET_BRANCH (e.g. where TARGET_BRANCH is develop):


    For a patch containing commits on your branch newer than those on the remote host TARGET_BRANCH (e.g. where REMOTE is origin and REMOTE/TARGET_BRANCH is origin/develop):


    For a patch containing only currently uncommitted changes:

    The test does not have assertions.

  • The test does not always pass when executed.

  • The Arrange or Act sections produce an error when executed.

  • The test may execute code that is potentially harmful to your system, leaks resources, or times out.

  • Creating partial tests is useful to developers for two reasons:

    • Firstly, it will save developers time. Instead of writing tests from scratch, they'll be able to use the partial tests as a starting point.

    • Secondly, it may help developers understand why Diffblue Cover was not able to complete the test automatically, especially in cases where the reason for not producing a test is lack of testability.

    Note that manually modified tests in test class files that are controlled by Diffblue (e.g. those suffixed with DiffblueTest) may be overwritten when running Cover the next time.

    For example, for method increment in the following class:

    Using dcover create --keep-partial-tests, Cover will create a partial test:

    The problem is clearly that Diffblue Cover has no opportunity to assert on the side effect of the increment method on field x, which is marked private. The developer could add a getter to MyClass:

    Running dcover create again (with or without --keep-partial-tests) would now create a complete test.

     repositories {
         mavenCentral()
     }
     dependencies {
         testCompile group: 'org.testng', name: 'testng', version: '7.8.0'
     }
     dependencies {
         testCompile("org.testng:testng:7.8.0")
     }
     repositories {
         mavenCentral()
     }
     dependencies {
         testCompile group: 'junit', name: 'junit', version: '4.13.2'
     }
     dependencies {
         testCompile("junit:junit:4.13.2")
     }
     dependencies {
         testCompile group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.8.0'
     }
     dependencies {
         testCompile("org.junit.jupiter:junit-jupiter:5.8.0")
     }
     dependencies {
         testCompile group: 'org.testng', name: 'testng', version: '7.8.0'
     }
     dependencies {
         testCompile("org.testng:testng:7.8.0")
     }
    public class DatabaseDao {
        public static class Inner {
            private Inner() {
            }
    
            public void myMethod(Inner inner) {
            }
        }
    }
    /**
      * Method under test: {@link DatabaseDao.Inner#myMethod(DatabaseDao.Inner)}
      */
    @Test
    @Disabled("TODO: Complete this test")
    void testInnerMyMethod() {
        // TODO: Complete this test.
        //   Reason: R008 Failed to instantiate class under test.
        //   Diffblue Cover was unable to construct an instance of DatabaseDao.Inner.
        //   Add a package-visible constructor or a factory method for the class under test.
        //   If such a method is already present but Diffblue Cover does not find it, it can
        //   be specified using custom rules for inputs:
        //   https://docs.diffblue.com/knowledge-base/cli/custom-inputs/
        //   This can happen because the factory method takes arguments, throws, returns null
        //   or returns a subtype.
        //   See https://diff.blue/R008
    
        // Arrange
        // TODO: Populate arranged inputs
        DatabaseDao.Inner inner = null;
        DatabaseDao.Inner inner1 = null;
    
        // Act
        inner.myMethod(inner1);
    
        // Assert
        // TODO: Add assertions on result
    }
    @Test
    public class testAppendTitle {
        ...
    }
    
    @Test
    public class testAppendTitle2 {
        ...
    }
        cd Module
        git diff origin/develop --relative > file.patch
        git diff origin/develop | out-file file.patch -encoding utf8
    git diff $(git rev-parse --abbrev-ref HEAD)...HEAD > $DIFFBLUE_PATCH
    git diff TARGET_BRANCH...HEAD > $DIFFBLUE_PATCH
    git fetch REMOTE
    git diff REMOTE/TARGET_BRANCH...HEAD > $DIFFBLUE_PATCH
    git diff > $DIFFBLUE_PATCH
    public class MyClass {
      private int x;
      public void increment() {
        ++x;
      }
    }
      @Test
      public void testIncrement() {
        // TODO: This test is incomplete.
        //   Reason: R002 Missing observers.
        //   Diffblue Cover was unable to create an assertion.
        //   Add getters for the following fields or make them package-private:
        //     MyClass.x
    
        // Arrange
        MyClass m = new MyClass();
    
        // Act
        m.increment();
      }
    public class MyClass {
      private int x;
      public void increment() {
        ++x;
      }
      public int getX() {
        return x;
      }
    }
    [@<argumentFile>...]
    ) - see
    for details.

    dcover help create

    Help - display inline help for the dcover create command (syntax, available arguments, and short descriptions).

    dcover version

    Check Version - display your Cover CLI version.

    Packages, classes, and methods
    Output Codes
    Cover Refactor
    Project configuration
    Create tests
    Argument files
    Diffblue Cover CI/CD integrations using alternative CI tools:

    Next steps...

    Learn about the additional tools provided with Cover Pipeline:

    What is Diffblue Cover

    [8 min read]

    An introduction and overview of Diffblue Cover including features, benefits, and how it works.

    Cover Pipeline for CI

    [3 min read]

    An overview of the options and features available when integrating Diffblue Cover into a CI pipeline.

    Free Trial Registration

    [1 min sign-up]

    If you haven't signed up for the Diffblue Cover trial yet, use this link to provide your details and get your license code.

    Quick Start - General

    [6 min read]

    General getting started guidance, applicable to most CI/CD tools.

    Quick Start - Jenkins

    [6 min read]

    General getting started guidance, applicable to Jenkins.

    Quick Start - Azure

    [6 min read]

    General getting started guidance, applicable to Azure.

    Quick Start - AWS

    [6 min read]

    General getting started guidance, applicable to AWS.

    Specs & Reqs

    [reference topic]

    Reference details - Diffblue Cover specifications and requirements.

    Licensing the Diffblue Cover Plugin for IntelliJ in offline mode is performed using Cover CLI.
    1. Install Diffblue Cover Plugin and install Diffblue Cover CLI.

    2. Before entering a license key, completely exit all instances of the IntelliJ IDE. Note that closing the project window is not sufficient.

    3. Follow the Cover CLI steps detailed in the tab above to activate your license in offline mode, using the Diffblue Cover CLI command dcover activate --offline

    4. Restart the IntelliJ IDE.

    5. You're now ready to write tests using Diffblue Cover Plugin.

    Activating Diffblue Cover CLI offline:

    1. Install Diffblue Cover CLI.

    2. Obtain your licence file and license key. To activate Diffblue Cover offline you will require your license file ls_activation.lic, along with your license key XXXX-XXXX-XXXX-XXXX. These can be obtained from: - Your Diffblue Cover welcome email received following license purchase. - Your organization's internal file/app/license store. - Or contact Diffblue Support for help finding this information.

    3. Run dcover license to prepare a directory for license installation:

    This will create an offline directory at:

    1. Copy ls_activation.lic to the Diffblue offline license directory:

    2. On Linux or macOS your home directory can be found at ~/.diffblue/offline/

    3. On Windows your user home can be found at C:\Users\<username>\.diffblue\offline\

    1. You're now ready to write tests using Diffblue Cover CLI.

    Diffblue Cover CLI (also as used in Docker images and Diffblue Cover Pipelines) can be configured using environment variables. Please note that environment variables for offline license activation will not work for the plugin.

    Obtain your license file and license key. To activate Diffblue Cover offline you will require your license file ls_activation.lic, along with your license key XXXX-XXXX-XXXX-XXXX. These can be obtained from: - Your Diffblue Cover welcome email received following license purchase. - Your organization's internal file/app/license store. - Or contact Diffblue Support for help finding this information.

    Configure the following environment variables:

    • DIFFBLUE_OFFLINE_LICENSE_ACTIVATION_FILE_CONTENTS with the contents of the ls_activation.lic

    • DIFFBLUE_LICENSE_KEY with the value of your license key.

    Windows only note: due to Windows environment variable size limitations (e.g. cmd.exe, Windows system variables, etc.), please configure using PowerShell to ensure the license activation file environment variable can be stored. Note that third party software such as git bash usually support larger environment variables.

    You can now activate your license with

    Distributing an offline license

    This section describes how to make an offline Enterprise license for Diffblue Cover available to users without them requiring their own activation or access to the license key. This is typically useful when users have managed environments where new software can be rolled out to their environment, or as an alternative to environment variables in a CI environment.

    1. First, the license will need to be activated as above using the Diffblue Cover CLI and provided ls_activation.lic and license key, e.g.: dcover activate --offline <DIFFBLUE LICENSE KEY> this will put a license.key file into <USER_HOME>/.diffblue/.

    2. The license.key file above can now be placed into the <USER_HOME>/.diffblue directory of any user and this will be recognized by Diffblue Cover (Plugin and CLI).

    Enterprise Edition
    Enterprise Edition
    remote license check
    Toolbox for tweaking Cover

    The three main levers to influence the behavior of Cover are:

    • Mocking

      • Cover automatically decides what to mock. However, sometimes it may not know at what level it should mock or try to instantiate classes that rather should be mocked. You can instruct Cover to try to mock certain classes.

    • Custom inputs

      • Cover automatically figures out which input values to use. However, some tests may require specific inputs, i.e. specific domain knowledge to initialize objects correctly. You can give hints to Cover to use certain values.

    • Custom setup

      • Some projects rely on static state or use custom application configuration mechanisms that need to be called before running any test. Cover will not be able to figure that out. You make Cover execute specfied custom setup so that it can build its tests upon it.

    There are multiple ways how to actuate these levers:

    Command line options:

    • for mocking: --mock, --mock-static, --mock-construction

    Cover Annotations:

    • for mocking

    • for custom inputs

    Diffblue rules:

    • for custom inputs

    Test factories:

    • for custom inputs of more complex types; usually in combination with annotations or Diffblue rules

    Custom base class:

    • for before/after methods and static setup

    Handling R013

    Cover did not find inputs that wouldn’t cause a trivial exception, e.g. NullPointerException.

    Causes:

    • Very specific input values are needed.

    • A hard-to-initialize object is needed.

    • Static (global) state needs to be initialized.

    Possible resolutions:

    • Provide custom inputs.

    • Rather than providing a fully initialized instance, mock the methods called from the code under test.

    • Initialize static state in a @Before method using a custom base class.

    Similar output codes: R008, R081, R082, R083.

    Handling R026

    Cover automatically figures out what Spring test context to load. Sometimes this fails because Spring configurations are missing for loading a test context.

    Resolution approach:

    1. Use command line option --keep-partial-test

    2. Run the created partial test and examine the obtained Spring exception

    3. Manually fix the code until the test passes

    4. Run Cover again

    (3) may involve

    • Adding an application-test.properties file.

    • Adding a Spring @Configuration class providing @Bean definitions for testing purposes.

    • Adding an additional class to the test context: use the --spring-configuration option, see .

    If you decide that a Spring context should not be loaded, use the --no-spring-tests option, see .

    Similar output codes: R027

    Handling R011

    Cover runs snippets of your code.

    • In order to protect your system, it runs them in a sandbox.

    • The sandbox forbids potentially dangerous operations, e.g. network access.

    Cause:

    • Your code calls a method that performs a forbidden operation.

    Possible resolutions:

    • Mock the operation so that it doesn’t get called.

    • Verify that the operation is harmless and run with --disable-sandbox. ⚠

    Similar output codes: R012

    Module 1
    Module 3
    Understanding output codes
    partial test
    Next steps...
    Cover Plugin Get Started
    IDE Unit Tests

    Core Maintenance

    [5 min read]

    Install, update, disable, enable, uninstall.

    What's New

    [reference topic]

    Summary and details of the latest Diffblue Cover updates and enhancements.

    Licensing

    [3 min read]

    A summary of the Diffblue licensing options.

    Settings

    [3 min read]

    A summary of available Cover Plugin settings.

    Telemetry

    [3 min read]

    Enable/disable and configure telemetry for Cover Plugin.

    Memory Management

    [3 min read]

    Tips for memory management.

    Log Files

    [3 min read]

    User and Support log files.

    eLearning

    Prefer video? No problem. Check out our overview video.

    1. Check the prerequisites

    A summary of Cover Reports prerequisites are listed below - see Specs & Reqs for full details.

    Client workstation - Cover Reports Contributor:

    • Diffblue Cover CLI

    • JaCoCo 0.8.3+

    • Network connectivity between the user's workstation and the Cover Reports server.

    Client workstation - Cover Reports User:

    • The latest version of Chrome, Edge, Safari, or Firefox with a screen resolution of 1920 x 1080 or higher.

    • Network connectivity between the user's workstation and the Cover Reports server.

    Server hosting Cover Reports - Cover Reports Administrator::

    • Docker Engine 20.10.17

    • 4GB RAM (8GB recommended), 2GB* minimum available disk space, 4 CPU cores.

    • 2GB Java heap allocation, 4GB recommended.

    • Docker Compose v2.10.2

    • Network connectivity between the server and client workstations.

    • Internet connection if using Docker Hub for install.

    2. Install Diffblue Cover Reports

    1. Using the link provided by Diffblue, download the Cover Reports .tar.gz file (e.g. diffblue-cover-reports-2023.07.02.tar.gz) to the server you plan to use to host Cover Reports. Contact Diffblue Support if you don't have the download link.

    2. From the directory containing the Cover Reports .tar.gz file, load the Docker bundle:

    1. In your shell, navigate to your preferred install directory (we'll now refer to this as $COVER_REPORTS_HOME). Using the link provided by Diffblue, download the Cover Reports Docker Compose file docker-compose.yml to $COVER_REPORTS_HOME. Contact if you don't have the download link.

    2. From the $COVER_REPORTS_HOME directory, start Cover Reports:

    1. Finally, open a browser on a client PC that has access to the Cover Reports server and navigate to the Cover Reports Home Page (<HOSTURL>:8080).

    1. To access the repository please and provide with your username. Diffblue Support will grant access according to your subscription terms.

    2. In your shell (from the server you plan to use to host Cover Reports), log in to Docker Hub using the docker login command with either your username and password or username and , for example:

    1. In your shell, navigate to your preferred install directory (we'll now refer to this as $COVER_REPORTS_HOME

    3. Create and upload a reports bundle

    Use Cover CLI to create a coverage data file for your project - this is referred to as a "reports bundle". You can do this on your own project, or you can use the example PetClinic Spring project that's used as part of the Get started - Cover CLI topic.

    Note that, to save you a little time, there's a demo project provided as part of Cover Reports so you can click Open Demo Project from the Reports splash screen and skip this Cover CLI step. If you or your organization have already used Cover Reports, this option won't be available.

    The optional arguments used with dcover create perform the following:

    • --coverage-reports is used create the coverage data files using Cover and JaCoCo.

    • --upload is used to define the URL to upload the reports bundle to - i.e. the URL for your Cover Reports server install. Note that HTTPS direct is currently not supported.

    4. Visualize your data

    Now the fun bit - taking a look at your coverage data. Please see Cover Reports User for a detailed guide through the visualisation dashboard.

    Next steps

    Now you're up and running with Cover Reports, use Cover CLI to create reports bundles for your own projects and start to build your data sets over time. In general, Cover Reports is pretty straightforward to use, especially from a UI perspective, but check out the Cover Reports topic for more details on using Cover Reports.

    Cover Pipeline
    Install and update Cover Reports
    Alternatives...

    Next steps...

    Now you've got the basics, move on to the core learning paths for Cover Plugin:

    What is Diffblue Cover

    [8 min read]

    An introduction and overview of Diffblue Cover including features, benefits, and how it works.

    Free Trial Registration

    [1 min sign-up]

    If you haven't signed up for the trial yet, use this link to provide your details and get your license code.

    Getting Started Video

    [5 min watch]

    Sit back and watch while we demonstrate how to download, install, license, and use Cover Plugin for IntelliJ.

    Getting Started Docs

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    To how many projects in total are you planning to roll out in the long-term?
  • How many teams work on these projects in total?

  • How many developers work on these projects in total?

  • Screensharing and log files.

    1. Please confirm which of the following the champions can share during working sessions:

      1. Console output of Diffblue Cover (contains identifier names).

      2. Cover log files (details can be provided on request).

      3. Cover Reports (coverage data).

      4. Snippets of build configurations (pom.xml, build.gradle, build.xml).

      5. Snippets of source code.

    2. Please confirm which of the following the champions can provide in support requests.

      1. Cover log files (details can be provided on request).

      2. Snippets of build configurations (pom.xml, build.gradle, build.xml).

  • Software and license distribution.

    1. Please describe the process from being notified about an update by a vendor to the software being available to a user. E.g. security scans, internal app stores.

    2. Please name a contact for software and license distribution.

  • Cover Reports installation.

    1. Please name a contact for installing the Cover Reports web-app so that it is accessible to all the teams.

  • Diffblue recommends to start onboarding with a handful of selected projects (3-5) from different teams. For each project, the following information should be provided.

    1. Name of the project.

    2. Name of the corresponding champion contact for each project.

    3. Name of the champion’s team and the team’s location in the organization hierarchy.

    4. SCM system (e.g. GitHub) of the project.

    5. CI system (e.g. Jenkins) of the project.

    6. Build System used by the project (e.g. Maven)

    7. Java version of the project.

    8. Operating system used by champion (e.g. Windows).

    9. IDE used by champion (e.g. IntelliJ).

    10. RAM (e.g. 16GB) and number of cores (e.g. 4) of the champion's workstation.

  • Once the information 1-5 has been received, Diffblue will send the software and licenses to the contact for software and license distribution.

    1. You then need to set up Cover Reports on a central server.

    2. If the champions' workstations do not meet the required specfications for running Cover then it is recommended to provision sufficiently powerful VMs with a development environment set up that allows to build the selected projects and run tests.

    3. Champions install Cover CLI, run preflight on the selected projects and send the log files to [email protected] for inspection to inform the subsequent Jumpstart agenda.

    Next steps...
    Cover CLI Get Started
    CLI Unit Tests

    Core Maintenance

    [5 min read]

    Install or update Cover CLI.

    What's New

    [reference topic]

    Summary and details of the latest Diffblue Cover updates and enhancements.

    Licensing

    [3 min read]

    A summary of the Diffblue licensing options.

    Telemetry

    [3 min read]

    Enable/disable and configure telemetry for Cover CLI.

    Memory Management

    [3 min read]

    Tips for memory management.

    Log Files

    [3 min read]

    User and Support log files.

    Dashboard

    Once logged in you will be presented with a dashboard which currently lists how many licenses you are managing.

    Orders

    Click on the Order button on the left hand menu bar to get a list of the orders you are managing. Each order can have 1 or more licenses associated with it. Click on an order to see the licenses it contains.

    Order details

    After clicking on an order you will see this Order details page. There are several tabs you can click on.

    If you click on License managers you can see a list of the license managers assigned to this order. You can also use the Add license manager button to add a new license manager.

    After clicking on the Add license manager button you will be given a short form to fill out. Input the email address, first name and last name. Take note of the automatically generated password or supply your own. These details are not automatically sent to the new license manager so you will have to email them yourself or provide them via some other channel.

    If you click on Licenses you will get a list of the license keys associated with the order. If there are many keys you will have multiple pages of licenses. The list includes the expiration date of the licenses and 'Status' indicates whether or not they have been activated.

    Licenses

    If you click on one of the licenses in the license list you will be taken to a page with more information about that license. This page also has a button where you can reset the activations for that license.

    Devices

    Clicking on the Devices tab on the License details screen will give you a list of all the devices that the license has been activated on. This includes information such as hostname and internal/external IP addresses.

    My profile

    You can edit your license manager profile by clicking on the My profile button in the left hand menu. From here you can change your first name, last name and also change your password.

    https://licenses.diffblue.com

    In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).

  • Select the Marketplace tab, search for Diffblue, and click Install. Your plugin will now be downloaded and installed.

  • When prompted, click Restart IDE to complete the install.

    1. Download the Diffblue Cover Plugin for IntelliJ as a .zip bundle from: &#xNAN;- The Diffblue website - Free Community Edition or Free Trial versions. &#xNAN;- The JetBrains Marketplace (IntelliJ Plugin Marketplace). &#xNAN;- The link sent to you via your Diffblue Cover welcome email. &#xNAN;- Your organization's internal file/app store.\

    2. In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).

    3. Click on the cog icon next to the Installed tab and select Install Plugin from Disk.... Navigate to the location of the plugin, select the zip file, and click OK.

    4. When prompted, click Restart IDE to complete the install.

    2. Apply a license

    Once IntelliJ has restarted, you'll be prompted for your license key (provided in your welcome email or by your organization) to activate the plugin. Alternatively, the license can be activated at any time from the IntelliJ toolbar Diffblue > Activate License. Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, see Licensing. Note that:

    • Applying a license provides access to the Teams and Enterprise Editions of Diffblue Cover.

    • Cover Plugin Community Edition is free to use but does require product verification to activate your perpetual license.

    • Offline license activation is available with the Diffblue Cover Enterprise Edition only. This can only be done through the CLI.

    • See Cover Editions and Licensing for more details.

    Update, Disable, Enable, Uninstall

    1. In IntelliJ, go to File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS) and highlight the Diffblue Plugin:

    • Click Update in the details panel to update to the latest version. Note that updating Cover Plugin may take a few minutes to complete and will require an IDE restart - you won't be able to create any tests for your projects while the update is progressing.

    • Select and click Disable from the drop down menu in the details panel to temporarily disable the plugin.

    • Select and click Enable from the drop down menu in the details panel to re-enable the plugin.

    • Select and click Uninstall from the drop down menu in the details panel to uninstall the plugin.

    1. When you're ready, click Restart IDE to complete the update.

    Displayed next to test classes and methods in project test files. Click the icon to update or delete tests for the method or class.

    Displayed next to your test methods in project test files. Click the icon to delete a test method.

    Indicates that Cover Plugin is unable to create tests for this method, unless the method is refactored to make it more testable. To allow Cover Plugin to write tests for such a method, the class should be extracted as an accessible named class.

    Indicates that Cover Plugin is unable to create tests that directly call this item, and that this is "by design". For example, Cover Plugin can't write tests for private methods.

    Write Tests

    Automatically write unit tests for your methods and classes directly in your IDE.

    Configure Your Projects

    Set up your projects to get the best tests from Diffblue Cover.

    Update Your Settings

    Make Cover Plugin work your way - update the Diffblue Cover settings in IntelliJ.

    Admin

    Get your admin done, including telemetry config, log files, memory management, etc.

    Improving Coverage

    [4 min read]

    This tutorial provides general information on improving your test coverage.

    Output Codes

    [5 reference topics]

    Reference details - Diffblue Cover output codes, messages, and descriptions.

    Working With Output Codes

    [12 topics]

    Useful hints and tips to help resolve a range of output codes.

    Refactor

    [4 min read]

    Use Cover Refactor to automatically suggest and apply refactorings to your code to help improve test coverage.

    Reports Intro

    [3 min read]

    An introduction and overview of Cover Reports.

    Generate & Upload Reports Bundles

    [8 min read]

    Specifically for Cover Reports Contributors (Developers) - how to generate and upload reports bundles using Cover CLI.

    Senior Developer
    Cover CLI Get Started
    CLI Unit Tests

    Improving Coverage

    [4 min read]

    This tutorial provides general information on improving your test coverage.

    Output Codes

    [5 reference topics]

    Reference details - Diffblue Cover output codes, messages, and descriptions.

    Working With Output Codes

    [12 topics]

    Useful hints and tips to help resolve a range of output codes.

    Refactor

    [4 min read]

    Use Cover Refactor to automatically suggest and apply refactorings to your code to help improve test coverage.

    Reports Intro

    [3 min read]

    An introduction and overview of Cover Reports.

    Generate & Upload Reports Bundles

    [8 min read]

    Specifically for Cover Reports Contributors (Developers) - how to generate and upload reports bundles using Cover CLI.

    What is Diffblue Cover

    [8 min read]

    An introduction and overview of Diffblue Cover including features, benefits, and how it works.

    Free Trial Registration

    [1 min sign-up]

    If you haven't signed up for the trial yet, use this link to provide your details and get your license code.

    Getting Started Video

    [7 min watch]

    A demonstration of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Getting Started Docs

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Get Started Video - Cover Plugin

    [5 min watch]

    A demonstration of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started Docs - Cover Plugin

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Developer - Cover CLI

    Use Cover CLI to write tests for your own projects.

    Administrator - Cover CLI

    General admin tasks.

    Cover Reports Intro

    [2 min read]

    A brief introduction to Cover Reports.

    Install & Update

    [6 min read]

    Install and update Cover Reports.

    Configuration Options

    [8 min read]

    Details of available configuration options.

    Database Backup

    [4 min read]

    Backup details for the for the default H2 database or optional (production grade environment) PostgreSQL database.

    SSO

    [5 min read]

    SSO prerequisites and considerations, plus NGINX setup guide links.

    Uninstall

    [3 min read]

    Uninstall details.

    What's New

    [reference topic]

    Summary and details of the latest Diffblue Cover updates and enhancements.

    Licensing

    [3 min read]

    A summary of the Diffblue licensing options.

    Cover Reports Intro

    [2 min read]

    A brief introduction to Cover Reports.

    Install & Update

    [6 min read]

    Install and update Cover Reports.

    Configuration Options

    [8 min read]

    Details of available configuration options.

    Database Backup

    [4 min read]

    Backup details for the for the default H2 database or optional (production grade environment) PostgreSQL database.

    SSO

    [5 min read]

    SSO prerequisites and considerations, plus NGINX setup guide links.

    Uninstall

    [3 min read]

    Uninstall details.

    What's New

    [reference topic]

    Summary and details of the latest Diffblue Cover updates and enhancements.

    Licensing

    [3 min read]

    A summary of the Diffblue licensing options.

    Online license activation

    How to activate your Diffblue Cover license online

    Requirements

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it is used. Offline license activation is available with the Enterprise Edition offline option only.

    To perform the license check Diffblue Cover needs an active internet connection to the following servers:

    • https://licensing.diffblue.com/

    • https://api.licensespring.com/

    The license check uses this connection to identify individual devices. Further details regarding the exact data exchanged are available in the .

    Activate a license

    Follow these steps to activate a license. Note that:

    • Cover Plugin Community Edition is free to use but does require product verification to activate your perpetual license.

    • These steps cover online license activation only.

    • Offline licensing for Cover CLI is available for Diffblue Cover Enterprise Edition only - see and .

    Once you install Cover Plugin for IntelliJ, you'll be prompted for your license key to activate the plugin. Alternatively, the license can be activated at any time from the IntelliJ toolbar Diffblue > Activate License.

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, see .

    To check your current license details, go to the Intellij toolbar Diffblue > View License Information.

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, as well as details of offline licensing (Enterprise Edition only), see .

    Configuring a proxy server

    Please ensure you have the Proxy Server details configured in the IntelliJ settings page and then restart IntelliJ:

    • Windows and Linux: File > Settings > Appearance and Behavior > System Settings > HTTP Proxy

    • macOS: IntelliJ IDEA > Preferences > Appearance and Behavior > System Settings > HTTP Proxy

    Please see the information below.

    Troubleshooting license server connections

    1. Check you have an active internet connection at all times when using Diffblue Cover.

    2. Ensure you can access https://licensing.diffblue.com/ via a web browser; you will automatically receive a confirmation message when this is successful.

    3. Ensure you can access https://api.licensespring.com/ via a web browser, you should see the message "Welcome to the LicenseSpring API".

    For further help troubleshooting licensing network connection issues, please contact .

    GitLab

    Integrate Diffblue Cover into your GitLab pipeline - Cover Pipeline for GitLab.

    Start here...

    Alternatives...

    Diffblue Cover CI/CD integrations using alternative CI tools:

    Next steps...

    Learn about Diffblue's developer tools:

    GitHub

    Integrate Diffblue Cover into your GitHub Actions workflows - Cover Pipeline for GitHub.

    Start here...

    Alternatives...

    Diffblue Cover CI/CD integrations using alternative CI tools:

    Next steps...

    Learn about Diffblue's developer tools:

    Run configurations

    How to configure the run configurations in IntelliJ for writing tests.

    Run configurations allow you to configure the environment variables and system properties that are used when Cover Plugin creates tests. It also allows you to manually specify the method, class, package, or prefix for writing tests.

    Dialog

    The IntelliJ run configuration dialog for Diffblue Cover contains the following elements:

    • Name - Provide a useful name for the run configuration.

    • Store as project file - If selected, the run configuration will be stored as a project file.

    • Test creation target - Select All in package, Class, Method, or Prefixes from the drop down to set the scope of items you're writing tests for. Enter the target details as appropriate.

    • Write skeleton tests - If selected, Cover Plugin will write skeleton tests instead of creating complete tests. See for more information.

    • Environment Variables - Provide a list of key/value pairs to set environment variables.

    To display the dialog box, go to Run > Edit Configurations. If needed, click Add New Configuration (the + button) and select Diffblue Cover.

    To access the system properties setting, click the Modify options button, and select Add VM Options. The VM option text box is added to the Run Configuration options - use this to add JVM system properties in the standard format, for example -Dkey1=value1.

    Creating a run configuration

    Automatic creation

    When you write tests with Cover Plugin a run configuration is created for your selection. For example, suppose we have the sample below:

    If you write tests for the method, the run configuration that is created will look like the following (to display the dialog box, go to Run > Edit Configurations and select the appropriate configuration from the list):

    You will notice there's a split between the class name and the method name, and that the method includes the signature of the method you've selected – this is the (Ljava/lang/String;)Z string after the colon.

    Manual creation

    To create a run configuration "manually", go to Run > Edit Configurations, click Add New Configuration (the + button) and select Diffblue Cover.

    First select the scope, then use the Browse action on the class/package (and method, if appropriate) to make your selection. If you've selected the method scope, the signature will be populated for you.

    Template

    If you have a particularly large list of system properties or environment variables that you would like to use every time you use Cover Plugin to write tests, you can specify a template. (File > New Projects Setup > Run Configuration Templates > Diffblue Cover). The values you specify will be used for any future run configurations.

    Prefixes

    If required, you can specify what packages, classes, or methods you want to restrict these operations to, by specifying one or more prefixes in the run configuration.

    Example: io.corebanking.Account


    Package example

    Specify a package entry point using the standard Java naming convention, plus an optional trailing dot.

    Syntax: <path>[.]


    Trailing dot: <path>.

    Example: com.a.

    Description: Write tests for all accessible methods within package <path> (in our example, com.a) and any sub-packages. For example, tests could be written for sub-packages com.a.B and com.a.b.C


    No trailing dot: <path>

    Example: com.a

    Description: Write tests for all accessible methods within any package that begins with <path> (in our example, com.a) and any sub-packages. For example, tests could be written for com.a, com.apple, com.apricot, com.apricot.pip, etc.


    Class example

    Specify a class entry point using the standard Java naming convention, plus an optional trailing dot.

    Syntax: <path>[.]


    Trailing dot: <path>.

    Example: io.diffblue.corebanking.account.Account.

    Description: Write tests for all accessible methods within class <path> only - in our example, io.diffblue.corebanking.account.Account.


    No trailing dot: <path>

    Example: io.diffblue.corebanking.account.Account

    Description: Write tests for all accessible methods within any class that begins with <path> - in our example, this could include ...Account and ...AccountException.


    Method example

    Specify a method entry point using the standard Java naming convention, plus an optional method descriptor.

    Syntax: <path>:[<methodDescriptor>]

    Example: io.diffblue.corebanking.account.Account.addToBalance:

    Description: Write tests for the specified method. If the optional method descriptor is omitted, all parameter and return types will be included.

    A method descriptor is a list of type descriptors that describe the parameter types and the return type of a method, in a single string. For more information on method descriptors, see section 2.1.4 of the .

    Free trial

    Trying out Diffblue Cover for the first time? Get up and running with the trial version of our two core developer tools - Cover Plugin for IntelliJ and Cover CLI.

    Interested in integrating Diffblue Cover into your CI/CD pipeline? Jump over to the .

    Start here...

    Telemetry

    Telemetry (usage data collection) in Cover Plugin for IntelliJ.

    Diffblue Cover captures telemetry (usage) data to help improve Cover services and features. Data is sent to the following endpoints:

    • Diffblue - Telemetry data is sent to Diffblue by default.

    • Cover Reports - Telemetry data can be sent to your Cover Reports instance (if required), allowing you to monitor Diffblue Cover usage across your organization.

    Further information on our data collection and policies is provided in the .

    docker load -i /path/diffblue-cover-reports-<version>.tar.gz
    cd demo-spring-petclinic
    dcover create --coverage-reports
        --upload=http://my-cover-reports-service:8080

    Snippets of source code.

    To activate your license, from a Windows PowerShell (Windows) or Terminal (macOS/Linux) enter the command dcover activate <license-key> - replace <license-key> with the license key provided in your welcome email or provided by your organization.

  • Entering multiple different license keys will overwrite the existing key.

  • You can check your license status by running the command dcover license

  • Diffblue Cover CLI utilizes the system Java proxy configurations; these can be set via the environment variable JVM_ARGS which details the proxy server FQDN and port, for example:

    As shown in this example:

    • JVM_ARGS passes extra options to the Java process from Diffblue Cover.

    • Passing -Dname=value sets a system property. You can use system properties to set the proxy config as shown here: https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html

    Reminder: Ensure that the environment variable JVM_ARGS is set permanently according to your operating system instructions.

    Ensure that any Proxy Server settings are correctly set up (see the bottom of this page).

  • Please speak to your network manager about allowing access to the URLs above, and checking that port 443 is open.

  • For Cover Plugin, restart IntelliJ.

  • Try temporarily disabling anti-virus, malware detector or any firewall software.

  • A detailed logfile is available which shows further diagnostic information about the license check process - please review the logs (Cover Plugin Log Files, Cover CLI Log Files).

  • Privacy Notice
    Offline license activation
    Online license activation
    Licensing
    HTTPS certificate errors
    Diffblue Support
    Editions
    Run dcover activate --offline <license key> to install the offline license:
    ➜  dcover license
    
    12:55:23.365 INFO  Diffblue Cover 2022.02.02
    12:55:23.368 INFO  There is no license linked to your product
    <USER_HOME>/.diffblue/offline/
    ➜  dcover activate --offline XXXX-XXXX-XXXX-XXXX
    
    15:48:35.064 INFO  Found an offline license file at '<USER_HOME>/.diffblue/offline/ls_activation.lic'
    15:48:35.494 INFO  Successfully activated offline license
    Creating skeleton tests
    ASM 4.0 A Java bytecode engineering library
    JVM_ARGS="-Dhttps.proxyHost=proxy.domain.com -Dhttps.proxyPort=8080"
    dcover activate --offline
    package com.example;
    
    public class StringUtils {
    
      public static boolean isPalindrome(final String s) {
        for (int i = 0; i < s.length() / 2; i++) {
          char first = s.charAt(i);
          char second = s.charAt(s.length() - 1 - i);
          if (first != second) {
            return false;
          }
        }
        return true;
      }
    }
    ). Using the link provided by Diffblue, download the Cover Reports Docker Compose file
    docker-compose.yml
    to
    $COVER_REPORTS_HOME
    . Contact
    if you don't have the download link.
  • From the $COVER_REPORTS_HOME directory, start Cover Reports:

    1. Finally, open your browser and navigate to the Cover Reports Home Page (<HOSTURL>:8080).

    Diffblue Support
    sign up to Docker Hub
    Diffblue Support
    Docker Hub Access Token
    Diffblue Support
    Alternatives...

    When you want to use the free trial, but you're only interested in using Diffblue Cover within an IDE, or via a command line:

    Next steps...

    Now you've got the basics, move on to the core learning paths for Cover Plugin and Cover CLI - these provide detailed guided learning paths for each product:

    DevOps Learning Paths

    What is Diffblue Cover

    [8 min read]

    An introduction and overview of Diffblue Cover including features, benefits, and how it works.

    Free Trial Registration

    [1 min sign-up]

    If you haven't signed up for the trial yet, use this link to provide your details and get your license code.

    Free Trial Video

    [7 min watch]

    Sit back and watch while we demonstrate how to download, install, license, and use Cover Plugin and Cover CLI to write tests for a sample project.

    Free Trial Docs

    [12 min read]

    Step-by-step details of how to download, install, license, and use Cover Plugin and Cover CLI to write tests for a sample project.

    Configure telemetry

    Telemetry can be configured (if required) using environment variables, and/or a properties file, on the host machine (where Diffblue Cover is being used). Note that these configuration settings apply to Cover Plugin and Cover CLI.

    • Environment variables always take priority and is the recommended method for configuring telemetry - variables listed below.

    • If you use a properties file, create a telemetry.properties file in the home directory under the .diffblue folder (for example, /users/joeblogs/.diffblue/telemetry.properties) and define one or more of the properties listed below.

    • If an individual environment variable or property is not found, the default value will be used.

    Environment variable
    Property
    Description
    Default

    DIFFBLUE_TELEMETRY_ EXTERNAL_ENABLED

    telemetry.

    external.

    enabled

    Enable (true) or disable (false) telemetry data for Diffblue. *

    true

    DIFFBLUE_TELEMETRY_ REPORTS_ENABLED

    telemetry.

    reports.

    enabled

    Enable (true) or disable (false) telemetry data for Cover Reports. **

    false

    DIFFBLUE_TELEMETRY_ REPORTS_HOSTNAME

    telemetry.

    reports.

    hostname

    Hostname of your Cover Reports server. **

    * Disabling the Diffblue endpoint for telemetry data is only available to Diffblue Cover Enterprise Edition customers.

    ** See your Cover Reports Administrator for help, if needed.

    If IntelliJ is open when making any telemetry configuration updates, you'll need to restart IntelliJ to apply the changes.

    Example telemetry.properties file:

    Manage configurations

    If you need to manage telemetry configuration across your organization, you can set the environment variables defined above (as needed) and apply these settings across your organization (for example, using a group policy).

    From release 2024.01.02, it is no longer possible to repackage Cover Plugin with telemetry disabled.

    Diffblue Privacy Notice

    GitHub

    Integrate the Diffblue Cover Action into your GitHub workflows.

    GitLab

    Incorporate the Diffblue Cover Project Integration into your GitLab pipeline.

    Get Started - Cover Plugin

    [8 min read]

    Download, install, license, and use Cover CLI to write tests for a sample project.

    Get Started - Cover CLI

    [8 min read]

    Download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started - Cover Optimize

    [3 min read]

    Speed up the time required to run Java unit tests by only running the tests related to a code change.

    Test Coverage

    Improve and manage test coverage.

    Support

    Where to get support for Diffblue Cover.

    Tutorials

    A range of tutorials covering topics such as implementing a code change and working with Kotlin projects.

    Cover Reports UI

    Using Cover Reports.

    Test Coverage

    Improve and manage test coverage.

    Support

    Where to get support for Diffblue Cover.

    Get Started Video - Cover CLI

    [7 min watch]

    A demonstration of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Get Started - Cover CLI

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Developer - Cover Plugin

    Use Cover Plugin to write tests for your own projects.

    Administrator - Cover Plugin

    General admin tasks.

    Cover Reports UI

    Using Cover Reports.

    Test Coverage

    Improve and manage test coverage.

    Support

    Where to get support for Diffblue Cover.

    Test Coverage

    Improve and manage test coverage.

    Support

    Where to get support for Diffblue Cover.

    Tutorials

    A range of tutorials covering topics such as implementing a code change and working with Kotlin projects.

    What is Diffblue Cover

    [8 min read]

    An introduction and overview of Diffblue Cover including features, benefits, and how it works.

    Introducing Cover Pipeline for GitLab

    [4 min watch]

    An overview of Cover Pipeline for GitLab and a brief demonstration of how to install, activate, and use Diffblue Cover directly within your GitLab pipeline.

    Free Trial Registration

    [1 min sign-up]

    If you haven't signed up for the Cover Pipeline for GitLab trial yet, use this link to provide your details and get your license code.

    Getting Started

    [6 min watch]

    A full demonstration of how to install, activate, configure, and use Diffblue Cover directly within your GitLab pipeline.

    Getting Started

    [6 min read]

    Step-by-step details of how to install, activate, configure, and use Diffblue Cover directly within your GitLab pipeline.

    GitLab Workflow

    [3 min read]

    Illustrative development workflows, with and without Cover Pipeline for GitLab.

    GitLab Config

    [6 min read]

    Configuration options including labels, environment config, and workflow config.

    Specs & Reqs

    [reference topic]

    Reference details - Diffblue Cover specifications and requirements.

    GitHub

    Incorporate the Diffblue Cover Action into your GitHub workflow.

    Other CI

    Integrate Cover CLI into your CI pipeline workflow - Jenkins, Azure, AWS.

    Get Started Video - IDE Only

    [5 min watch]

    A demonstration of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started Docs - IDE Only

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started Video - CLI Only

    [7 min watch]

    A demonstration of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Get Started Docs - CLI Only

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover CLI to write tests for a sample project.

    What is Diffblue Cover

    [8 min read]

    An introduction and overview of Diffblue Cover including features, benefits, and how it works.

    Introducing Cover Pipeline for GitHub

    [3 min watch]

    An overview of Cover Pipeline for GitHub and a brief demonstration of how to activate, configure, and use Diffblue Cover directly within your GitHub Actions workflows.

    Free Trial Registration

    [1 min sign-up]

    If you haven't signed up for the Cover Pipeline for GitHub trial yet, use this link to provide your details and get your license code.

    Getting Started Video

    [4 min watch]

    A full demonstration of how to activate, configure, and use Diffblue Cover directly within your GitHub Actions workflows.

    Getting Started Docs

    [6 min read]

    Step-by-step details of how to activate, configure, and use Diffblue Cover directly within your GitHub Actions workflows.

    GitHub Workflow

    [3 min read]

    Illustrative development workflows, with and without Cover Pipeline for GitHub.

    GitHub Config

    [6 min read]

    Configuration options including labels, environment config, and workflow config.

    Specs & Reqs

    [reference topic]

    Reference details - Diffblue Cover specifications and requirements.

    GitLab

    Incorporate the Diffblue Cover Project Integration into your GitLab pipeline.

    Other CI

    Integrate Cover CLI into your CI pipeline workflow - Jenkins, Azure, AWS.

    Get Started Video - IDE Only

    [5 min watch]

    A demonstration of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started Docs - IDE Only

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started Video - CLI Only

    [7 min watch]

    A demonstration of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Get Started Docs - CLI Only

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Unit tests (IDE)

    Use Diffblue Cover within the IntelliJ IDE to create tests for your methods and classes.

    Before starting this learning path, we recommend that you first complete the Cover Plugin Get Started path.

    Start here...

    Know more...

    Next steps...

    Test Naming

    Instructions on how to define the naming system used for tests generated by the Cover Plugin for IntelliJ.

    Test classes and methods created by Diffblue Cover are named after the class and methods under test using configurable templates. To change the naming, go to Diffblue > Change Settings in IntelliJ and update the Test Naming section as needed.

    Class Name Template

    Description: Used to define the test class naming convention for tests written by Diffblue Cover. The ${CLASS} variable will be substituted with the name of the class under test.

    Default: ${CLASS}DiffblueTest

    Example: ${CLASS}CreatedTest

    Method Name Template

    Description: Used to define the test method naming convention for tests written by Diffblue Cover. The following variables can be used:

    • ${INNER} - substituted with the name of the inner class for the method under test. If there's no inner class this will be an empty string.

    • ${UNIT} - usually substituted with the name of the method under test. Where the unit under test comprises multiple methods (getters and setters, equals and hash code) the more general unit under test name is used.

    • ${METHOD} - substituted with the name of the first method under test, typically the only method under test. To avoid duplication, do not use ${UNIT}

    Default: test${INNER}${UNIT}${_}${GIVEN}${_}${WHEN}${_}${THEN}

    Example: aitest${INNER}${UNIT}

    Descriptive Test Names

    Descriptive ${GIVEN} , ${WHEN} and ${THEN} summaries are populated when disambiguating multiple tests for the same method under test, and are added to the test method name up to a maximum of 80 characters. When descriptive test names are enabled they are additionally used to provide improved javadoc comments, and to provider clearer test display names when the test framework supports it.

    When ${UNIT} is describes a single method under test that has overloads then the method under test's arguments are additionally described.

    Descriptive test names are enabled by default but can be disabled via the "Descriptive Test Names" setting.

    Numeric Disambiguation

    Disambiguation between tests of the same name is performed automatically using sequential numbering:

    Diffblue Learning

    Get the most out of Diffblue Cover - Read, Watch, Learn - select the guided learning path to get what you need.

    Get started

    Get started with Diffblue Cover - download, install, license, and play:

    Unit tests (CLI)

    Use Diffblue Cover from a command line to create tests for your projects.

    Before starting this learning path, we recommend that you first complete the path.

    Start here...

    Test examples

    In this topic we show both the input source code, and the tests written by Diffblue Cover, for code of varied complexity, accompanied by a detailed narrative to help you further understand tests created by Diffblue Cover.


    Basic assertions

    This is a simple example of Spring Service source code with a trivial getter. Cover can write a Spring Boot test for the getter in a service provider by inlining Arrange, Act, and Assert.

    docker compose up -d
    docker login -u <username> <password_or_token>
    docker compose up -d
    # Copyright 2021-2024 Diffblue Limited. All Rights Reserved.
    # Example telemetry.properties file
    telemetry.external.enabled=true
    telemetry.reports.enabled=true
    telemetry.reports.hostname=localhost
    telemetry.reports.port=8080
    telemetry.reports.scheme=http

    localhost

    DIFFBLUE_TELEMETRY_ REPORTS_PORT

    telemetry.

    reports.

    port

    Port number of your Cover Reports instance **

    8080

    DIFFBLUE_TELEMETRY_ REPORTS_SCHEME

    telemetry.

    reports.

    scheme

    Protocol used to communicate with Cover Reports - http or https **

    http

    and
    ${METHOD}
    together.
  • ${GIVEN} - substituted with a summary of the conditions before testing, or else blank.

  • ${WHEN} - substituted with a summary of the conditions under test, or else blank.

  • ${THEN} - substituted with a summary of the test's consequences, or else blank.

  • ${_} - substituted with an underscore, or blank if there are no values to separate.

  • Source

    Test written by Diffblue Cover


    Mocking

    This is a class that contains two methods to upload and download a file to/from an Amazon S3 bucket. As the Amazon S3 bucket is a cloud storage mechanism, the test for this class/methods requires dependency injection. Cover can mock these types of dependencies and tests downloadFileFromBucket method by asserting the expected S3Object and the downloaded S3Object using the method.

    Source

    Tests written by Diffblue Cover


    OS agnostic assertions

    This example returns time in a different format. Cover writes a test to assert date and time that is not dependent on operating system or local time zones.

    Source

    Test written by Diffblue Cover


    Example containing logic

    In this example, Cover writes two tests to cover each pathway through the conditional - a test which adds 10 to the balance and asserts the new balance should be 20 and a second test where the account is closed.

    Source

    Test written by Diffblue Cover


    Example of complex logic

    This example code has three branches - Cover covers 100% of branches and creates three tests for three cases using existing enum values.

    Source

    Tests written by Diffblue Cover


    Testing trivial methods

    Diffblue Cover CLI deliberately does not test trivial methods such as getters, setters, constructors and factory methods to avoid creating large quantities of noisy tests that do not contribute to overall coverage. There isn't a benefit to be gained from testing these trivial methods directly as, for example, getters and setters simply access attributes so there is no actual logic to be tested. Similarly, constructors and factory methods also contain little or no logic. If Diffblue Cover CLI did test such methods directly, a minor coverage increase might be gained, but this "improvement" would be meaningless in terms of improving code quality.

    Ultimately these trivial methods will be covered when Cover generates tests for other methods that call these trivial methods. Diffblue recommends improving the percentage of coverage using the many options within the product, as shown in the Commands & Arguments topic.

    public class UserAccessCreatedTest {
    
        public String currentUser;
    
        ...
    }
    @Test
    public void aitestGettersAndSetters() {
        // Arrange
        ComponentPojo componentPojo = new ComponentPojo();
    
        // Act
        componentPojo.setName("Name");
        componentPojo.setSize(3);
        String actualName = componentPojo.getName();
        // Assert that nothing has changed
        assertEquals("Name", actualName);
        assertEquals(3, componentPojo.getSize());
    }
    
    @Test
    public void aitestEqualsAndHashCode() {
        // Arrange
        DoubleArgumentType doubleArgResult = DoubleArgumentType.doubleArg(10.0d, 10.0d);
    
        // Act and Assert
        assertEquals(doubleArgResult, doubleArgResult);
        int expectedHashCodeResult = doubleArgResult.hashCode();
        assertEquals(expectedHashCodeResult, doubleArgResult.hashCode());
    }
    /**
     * Test {@link BaseEntity#isNew()}; given BaseEntity Id one; then returns false.
     * <p>
     * Method under test: {@link BaseEntity#isNew()}
     */
    @Test
    @DisplayName("Test isNew(); given BaseEntity Id one; then returns false")
    void testIsNew_givenBaseEntityIdOne_thenReturnsFalse() {
    	// Arrange
    	BaseEntity baseEntity = new BaseEntity();
    	baseEntity.setId(1);
    
    	// Act and Assert
    	assertFalse(baseEntity.isNew());
    }
    
    /**
     * Test {@link BaseEntity#isNew()}; given BaseEntity; then returns true.
     * <p>
     * Method under test: {@link BaseEntity#isNew()}
     */
    @Test
    @DisplayName("Test isNew(); given BaseEntity; then returns true")
    void testIsNew_givenBaseEntity_thenReturnsTrue() {
    	// Arrange, Act and Assert
    	assertTrue((new BaseEntity()).isNew());
    }
    /**
     * Test {@link Owner#getPet(String)} with name.
     * <p>
     * Method under test: {@link Owner#getPet(String)}
     */
    @Test
    @DisplayName("Test getPet(String) with name")
    void testGetPetWithName() {
    	// Arrange, Act and Assert
    	assertNull((new Owner()).getPet("Bella"));
    }
    
    /**
     * Test {@link Owner#getPet(String, boolean)} with name, ignoreNew.
     * <p>
     * Method under test: {@link Owner#getPet(String, boolean)}
     */
    @Test
    @DisplayName("Test getPet(String,boolean) with name, ignoreNew")
    void testGetPetWithNameIgnoreNew() {
    	// Arrange, Act and Assert
    	assertNull((new Owner()).getPet("Bella", true));
    }
    @Test
    public void testAppendTitle() {
        ...
    }
    
    @Test
    public void testAppendTitle2() {
        ...
    }
    import org.springframework.stereotype.Service;
    
    @Service
    public class SimpleService
    {
      public String getValue() {
        return "a really simple service";
      }
    }
    @SpringBootTest
    @RunWith(org.springframework.test.context.junit4.SpringRunner.class)
    public class SimpleServiceDiffblueTest {
      @Autowired
      private SimpleService simpleService;
      @Test
      public void diffbluetestGetValue() {
        // Arrange, Act and Assert
        assertEquals("a really simple service", this.simpleService.getValue());
      }
    }
    @Service
    public class AmazonService {
    
      @Autowired
      private AmazonS3 s3client;
    
      public PutObjectResult uploadFileToBucket(String bucketName, String key, File file) {
        return s3client.putObject(bucketName, key, file);
      }
    
      public S3Object downloadFileFromBucket(String bucketName, String key) {
        return s3client.getObject(bucketName, key);
      }
    }
    @SpringBootTest
    public class AmazonServiceDiffblueTest {
      @MockBean
      private AmazonS3Client amazonS3Client;
      @Autowired
      private AmazonService amazonService;
      @Test
      public void diffbluetestUploadFileToBucket() {
        // Arrange
        PutObjectResult putObjectResult = new PutObjectResult();
        putObjectResult.setContentMd5("file-hash");
        when(this.amazonS3Client.putObject(or(isA(String.class), isNull()), or(isA(String.class), isNull()),
            or(isA(File.class), isNull()))).thenReturn(putObjectResult);
    
        // Act and Assert
        assertSame(putObjectResult, this.amazonService.uploadFileToBucket("foo", "foo",
            Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile()));
      }
      @Test
      public void diffbluetestDownloadFileFromBucket() throws UnsupportedEncodingException {
        // Arrange
        StringInputStream objectContent = new StringInputStream("file-name");
        S3Object s3Object = new S3Object();
        s3Object.setObjectContent(objectContent);
        when(this.amazonS3Client.getObject(or(isA(String.class), isNull()), or(isA(String.class), isNull())))
            .thenReturn(s3Object);
    
        // Act and Assert
        assertSame(s3Object, this.amazonService.downloadFileFromBucket("foo", "foo"));
      }
    }
    public class TimeInAliceWonderland {
    
      private static final String DODO_DATETIME_FORMAT = "ss:mm:HH dd-MMM-yyyy";
    
      public static String reformatDodoDateTime(Date humanDate) {
        Map<String, DateFormat> dateFormatMap = new HashMap<>();
        dateFormatMap.put(DODO_DATETIME_FORMAT, new SimpleDateFormat(DODO_DATETIME_FORMAT));
        return dateFormatMap.get(DODO_DATETIME_FORMAT).format(humanDate);
      }
    }
    @Test
      public void diffbluetestReformatDodoDateTime() {
        LocalDateTime atStartOfDayResult = LocalDate.of(1970, 1, 1).atStartOfDay();
        assertEquals("00:00:00 01-Jan-1970", TimeInAliceWonderland
            .reformatDodoDateTime(
                Date.from(atStartOfDayResult.atZone(ZoneId.systemDefault()).toInstant())));
      }
    public class Account {
      private final long accountNumber;
      private final Client client;
      private long currentBalance;
      private String accountName;
      private AccountState accountState;
    
      public Account(final long accountNumber, final Client client, final long amount) {
        this.accountNumber = accountNumber;
        this.client = client;
        currentBalance = amount;
        accountName = "Current";
        accountState = AccountState.OPEN;
      }
    
      public long getCurrentBalance() {
        return currentBalance;
      }
    
      public void addToBalance(final long amount) throws AccountException {
        if (getAccountState() != AccountState.OPEN) {
          throw new AccountException("Cannot add to balance, account is closed.");
        }
        currentBalance += amount;
      }
     @Test
      public void diffbluetestAddToBalance() throws AccountException {
        // Arrange
        Account account = new Account(1234567890L, new Client("Carlos Welch"), 10L);
    
        // Act
        account.addToBalance(10L);
    
        // Assert
        assertEquals(20L, account.getCurrentBalance());
      }
    public class VirtualSnackCupboard {
    
      public static Snack whatCanISnackNow(int oClock) {
        if (oClock == 10) {
          return Snack.CHOCOLATE;
        } else if (oClock == 15) {
          return Snack.CAKES;
        } else {
          return Snack.VEGGIE;
        }
      }
      enum Snack {VEGGIE, CHOCOLATE, CAKES}
    }
      public void diffbluetestPickSnack() {
        assertEquals(VirtualSnackCupboard.Snack.CHOCOLATE, VirtualSnackCupboard.whatCanISnackNow(10));
        assertEquals(VirtualSnackCupboard.Snack.CAKES, VirtualSnackCupboard.whatCanISnackNow(15));
        assertEquals(VirtualSnackCupboard.Snack.VEGGIE, VirtualSnackCupboard.whatCanISnackNow(0));
      }
    Achievements:

    Developer

    Detailed learning paths targeted at developers:

    Achievements:

    DevOps

    Detailed learning paths targeted at DevOps:

    Achievements:

    Administrator

    Detailed learning paths targeted at "administrators" - manage and maintain Diffblue Cover for you, or your organization:

    Achievements:

    Test coverage

    Improve, monitor, and manage your test coverage:

    Achievements:

    Just the basics

    Diffblue Cover basic concepts.

    Free Trial

    Get started with the free trial (IDE and Command Line) and create tests for a sample project.

    Cover Plugin (IDE)

    A focus on the IntelliJ IDE. Get started with Cover Plugin and create tests for sample methods and classes directly in your IDE.

    Cover CLI (Command Line)

    A focus on the command line. Get started with Cover CLI and create tests for an entire sample project using the CLI tool.

    Know more...

    Next steps...

    Cover CLI Get Started

    Writing Tests

    [2 min read]

    A summary of how to write tests using Cover CLI.

    Command Summary

    [2 min read]

    A summary of the core Cover CLI commands and arguments.

    Cover CLI Overview

    [29 min watch]

    Get a complete overview of Cover CLI with this tutorial video.

    Commands & Arguments

    [reference]

    Reference topic - details of all available commands and arguments.

    Test Examples

    [5 min read]

    Unit test examples of varying complexity.

    Project Configuration & Dependencies

    [9 topics]

    Making sure your project configuration and dependencies meet the requirements needed to use Diffblue Cover.

    Preflight Checks

    [5 min read]

    Diffblue Cover's preflight features for checking the suitability of your environment.

    Output Codes

    [5 reference topics]

    Reference details - Diffblue Cover output codes, messages, and descriptions.

    Specs & Reqs

    [reference topic]

    Reference details - Diffblue Cover specifications and requirements.

    Get Started Video - IDE Only

    [5 min watch]

    A demonstration of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started Docs - IDE Only

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover Plugin to write tests for a sample project.

    Get Started Video - CLI Only

    [7 min watch]

    A demonstration of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Get Started Docs - CLI Only

    [8 min read]

    Step-by-step details of how to download, install, license, and use Cover CLI to write tests for a sample project.

    Developer - Cover Plugin

    Use Cover Plugin to write tests for your own projects.

    Administrator - Cover Plugin

    General admin tasks.

    Developer - Cover CLI

    Use Cover CLI to write tests for your own projects.

    Administrator - Cover CLI

    General admin tasks.

    Writing Tests

    [2 min read]

    A summary of how to write tests using Cover Plugin in IntelliJ.

    Gutter Icons

    [2 min read]

    A summary of gutter icons features.

    Menu Options

    [2 min read ]

    A summary of the Diffblue menu options.

    Test Examples

    [5 min read]

    Unit test examples of varying complexity.

    Project Configuration & Dependencies

    [3 min read]

    Making sure your project configuration and dependencies meet the requirements needed to use Diffblue Cover.

    Specs & Reqs

    [reference topic]

    Reference details - Diffblue Cover specifications and requirements.

    Output Codes

    [5 reference topics]

    Reference details - Diffblue Cover output codes, messages, and descriptions.

    Working With Output Codes

    [12 topics]

    Useful hints and tips to help resolve a range of output codes.

    Run Configurations

    [4 min read ]

    Configure the environment variables and system properties used when Cover Plugin creates tests.

    Settings

    [3 min read]

    A summary of available Cover Plugin settings.

    Partial Tests

    [4 min read]

    Creating partial (incomplete) tests.

    Skeleton Tests

    [4 min read]

    Creating skeleton (outline) tests.

    Test Naming

    [4 min read]

    Test naming config and defaults.

    Test Formatting

    [4 min read]

    Configure the format of tests written by Cover Plugin.

    Test Insertion Order

    [2 min read]

    Test method ordering in test classes.

    Cover Plugin Admin

    Manage and maintain Cover Plugin.

    Test Coverage

    Improve and manage test coverage.

    Tutorials

    A range of tutorials covering topics such as implementing a code change and working with Kotlin projects.

    Test examples

    In this topic we show both the input source code, and the tests written by Diffblue Cover, for code of varied complexity, accompanied by a detailed narrative to help you further understand tests created by Diffblue Cover.


    Basic assertions

    This is a simple example of Spring Service source code with a trivial getter. Cover can write a Spring Boot test for the getter in a service provider by inlining Arrange, Act, and Assert.

    Source

    Test written by Diffblue Cover


    Mocking

    This is a class that contains two methods to upload and download a file to/from an Amazon S3 bucket. As the Amazon S3 bucket is a cloud storage mechanism, the test for this class/methods requires dependency injection. Cover can mock these types of dependencies and tests the downloadFileFromBucket method by asserting the expected S3Object and the downloaded S3Object using the method.

    Source

    Tests written by Diffblue Cover


    OS agnostic assertions

    This example returns time in a different format. Cover writes a test to assert date and time that is not dependent on operating system or local time zones.

    Source

    Test written by Diffblue Cover


    Example containing logic

    In this example, Cover writes two tests to cover each pathway through the conditional - a test which adds 10 to the balance and asserts the new balance should be 20 and a second test where the account is closed.

    Source

    Test written by Diffblue Cover


    Example of complex logic

    This example code has three branches - Cover covers 100% of branches and creates three tests for three cases using existing enum values.

    Source

    Tests written by Diffblue Cover


    Testing trivial methods

    Diffblue Cover CLI deliberately does not test trivial methods such as getters, setters, constructors and factory methods to avoid creating large quantities of noisy tests that do not contribute to overall coverage. There isn't a benefit to be gained from testing these trivial methods directly as, for example, getters and setters simply access attributes so there is no actual logic to be tested. Similarly, constructors and factory methods also contain little or no logic. If Diffblue Cover CLI did test such methods directly, a minor coverage increase might be gained, but this "improvement" would be meaningless in terms of improving code quality.

    Ultimately these trivial methods will be covered when Cover generates tests for other methods that call these trivial methods. Diffblue recommends improving the percentage of coverage using the many options within the product, as shown in the topic.

    Get started - Cover Pipeline

    This topic details how to use Diffblue Cover to write tests for your project as part of a CI pipeline. It outlines the basic commands that you will need to add to your CI scripts, and provides general information to understand the key steps - for specific CI tools, refer to the following:

    • Cover Pipeline for GitLab

    • Cover Pipeline for GitHub

    • Quick Start - Jenkins

    Assumptions

    This topic assumes that you have:

    • A basic understanding of Cover CLI - see .

    • A Maven or Gradle project that:

      • Compiles.

      • Does not have non-compiling or failing tests.

    Summary

    To integrate Diffblue Cover into your CI pipeline, we will guide you through creating a CI script that:

    1. Building the project

    To run Diffblue Cover CLI your project must be built. Running the project’s tests is not required, and you will save time by skipping them, but they do need to compile and pass. For example, you can use the following command to build a Maven project while skipping the tests:

    2. Downloading and activating Diffblue Cover CLI

    You need to give the CI run access to the Diffblue Cover files and activate the dcover license in order to write tests.

    This step assumes that you have a URL with the Diffblue Cover CLI release zip and the license key for online activation during the CI run. If your license allows it you may wish to install Diffblue Cover with offline activation. See .

    You will need to add two secret variables which, here, will be represented as environment variables:

    • The first secret variable with the name DIFFBLUE_COVER_URL and the value set to the URL of the Diffblue Cover CLI release zip file.

    • The second with the name DIFFBLUE_COVER_LICENSE_KEY and the value set to your Diffblue Cover license key.

    Append the code for getting, unzipping, and activating dcover, to your script.

    This will put the Diffblue Cover files into the dcover directory in the root of the workspace. The files contain a script called dcover which has the relative path dcover/dcover (or dcover\dcover.bat in Windows environments). The script is added to your PATH variable so that you can invoke Diffblue Cover CLI as dcover (or dcover.bat).

    Push the changes so that your CI is triggered - ensure that you can see the successful activation of dcover in your CI output before moving on. You will see a line starting with "Successfully activated key" if this was successful. If Diffblue Cover did not successfully activate, please see or contact .

    3. Running Diffblue Cover CLI to create tests

    Now that Diffblue Cover is running in CI, you can use it to write tests. The next two items show how to write tests for a single module, and then how to extend this to all modules.

    Creating tests for a single module:

    Choose a module to test in your project. Append the following to your workflow file, changing moduleToTest to a module in your project or, if your project does not have modules, --working-directory moduleToTest can be removed or changed to --working-directory. Note that the --batch option makes the output more suitable for CI, as it ensures the CI logs are not cluttered with progress bar output.

    Push the changes so that dcover runs in the CI. Once successfully complete, you should expect to see output that looks like this:

    If you don't see this output, the dcover command may need a small modification for your project, or dependencies adding, until it works. The output gives you warnings along the way to guide you. See for more information.

    Depending on the size of your module/project, creating tests could take a while. You may wish to restrict test creation to a single class by specifying its fully qualified name:

    Creating tests for all modules:

    To write tests for all the modules, you can use a loop as follows:

    4. Committing the created tests to a branch

    To see the new tests created in the previous step in your project, you need to commit them and push back to the repository. Depending on your CI tool you may also need to configure a Git user to create the commit. We recommend creating a service account for this.

    To commit the tests, append the following to your script. This will check for any changes to Diffblue tests, add them to a commit and push to your branch.

    Note: Be careful not to create an infinite CI loop here. We recommend checking the author of each commit to ensure you're not creating tests for a commit authored by your Diffblue service account.

    Next steps

    In this topic we've outlined the basic commands that you will need to add to your CI scripts, but we've only provided general information to understand the key steps - for specific CI tools, refer to the following:

    Diffblue Cover - one AI

    Diffblue Cover is also provided as an IDE plugin tool so you can write tests with one click in the IntelliJ IDE (see ) and as a developer CLI tool to write tests for your entire project, all in one hit (see ).

    But Cover CLI, Cover Plugin, and Cover Pipeline are not mutually exclusive, in fact they make perfect partners. Use Cover Plugin within the IntelliJ IDE to write and check unit tests for your application during development, and also use Cover CLI directly from the IntelliJ Console or your OS command line to access the wider and deeper functionality provided by Cover CLI - finally, use Cover Pipeline within your CI tool to automate the whole process and provide consistency across your organization.

    Get started - Cover CLI

    Get started with Diffblue Cover CLI - in short, install the CLI tool, apply your license, and you're ready to go. This topic also provides an example and some next steps.

    If you've already done this as part of your free trial, you may want to skip this and jump straight to the details, or perhaps you want to update to the latest version - see .

    eLearning

    Short on time? If you'd like a fast-track experience check out our getting started video. [6 min]

    Commands & Arguments

    Is stored in a Git repository with a CI tool enabled.

  • A basic understanding of your chosen CI tool.

  • The ability to store secrets variables for your CI tool.

  • Diffblue Cover CLI release zip stored in the cloud, along with an appropriate license key.

  • Quick Start - AWS Codebuild
    Quick Start - Azure Pipelines
    Quick Start - AWS Codebuild
    Get started - Cover CLI
    Builds your project.
    Downloads and activates Diffblue Cover CLI.
    Runs Diffblue Cover to create tests.
    Commits the created tests to a branch.
    Licensing
    Licensing
    Diffblue Support
    Commands & Arguments
    Cover Pipeline for GitLab
    Cover Pipeline for GitHub
    Quick Start - Jenkins
    Quick Start - Azure Pipelines
    Get started - Cover Plugin
    Get started - Cover CLI
    import org.springframework.stereotype.Service;
    
    @Service
    public class SimpleService
    {
      public String getValue() {
        return "a really simple service";
      }
    }
    @SpringBootTest
    @RunWith(org.springframework.test.context.junit4.SpringRunner.class)
    public class SimpleServiceDiffblueTest {
      @Autowired
      private SimpleService simpleService;
      @Test
      public void diffbluetestGetValue() {
        // Arrange, Act and Assert
        assertEquals("a really simple service", this.simpleService.getValue());
      }
    }
    @Service
    public class AmazonService {
    
      @Autowired
      private AmazonS3 s3client;
    
      public PutObjectResult uploadFileToBucket(String bucketName, String key, File file) {
        return s3client.putObject(bucketName, key, file);
      }
    
      public S3Object downloadFileFromBucket(String bucketName, String key) {
        return s3client.getObject(bucketName, key);
      }
    }
    @SpringBootTest
    public class AmazonServiceDiffblueTest {
      @MockBean
      private AmazonS3Client amazonS3Client;
      @Autowired
      private AmazonService amazonService;
      @Test
      public void diffbluetestUploadFileToBucket() {
        // Arrange
        PutObjectResult putObjectResult = new PutObjectResult();
        putObjectResult.setContentMd5("file-hash");
        when(this.amazonS3Client.putObject(or(isA(String.class), isNull()), or(isA(String.class), isNull()),
            or(isA(File.class), isNull()))).thenReturn(putObjectResult);
    
        // Act and Assert
        assertSame(putObjectResult, this.amazonService.uploadFileToBucket("foo", "foo",
            Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile()));
      }
      @Test
      public void diffbluetestDownloadFileFromBucket() throws UnsupportedEncodingException {
        // Arrange
        StringInputStream objectContent = new StringInputStream("file-name");
        S3Object s3Object = new S3Object();
        s3Object.setObjectContent(objectContent);
        when(this.amazonS3Client.getObject(or(isA(String.class), isNull()), or(isA(String.class), isNull())))
            .thenReturn(s3Object);
    
        // Act and Assert
        assertSame(s3Object, this.amazonService.downloadFileFromBucket("foo", "foo"));
      }
    }
    public class TimeInAliceWonderland {
    
      private static final String DODO_DATETIME_FORMAT = "ss:mm:HH dd-MMM-yyyy";
    
      public static String reformatDodoDateTime(Date humanDate) {
        Map<String, DateFormat> dateFormatMap = new HashMap<>();
        dateFormatMap.put(DODO_DATETIME_FORMAT, new SimpleDateFormat(DODO_DATETIME_FORMAT));
        return dateFormatMap.get(DODO_DATETIME_FORMAT).format(humanDate);
      }
    }
    @Test
      public void diffbluetestReformatDodoDateTime() {
        LocalDateTime atStartOfDayResult = LocalDate.of(1970, 1, 1).atStartOfDay();
        assertEquals("00:00:00 01-Jan-1970", TimeInAliceWonderland
            .reformatDodoDateTime(
                Date.from(atStartOfDayResult.atZone(ZoneId.systemDefault()).toInstant())));
      }
    public class Account {
      private final long accountNumber;
      private final Client client;
      private long currentBalance;
      private String accountName;
      private AccountState accountState;
    
      public Account(final long accountNumber, final Client client, final long amount) {
        this.accountNumber = accountNumber;
        this.client = client;
        currentBalance = amount;
        accountName = "Current";
        accountState = AccountState.OPEN;
      }
    
      public long getCurrentBalance() {
        return currentBalance;
      }
    
      public void addToBalance(final long amount) throws AccountException {
        if (getAccountState() != AccountState.OPEN) {
          throw new AccountException("Cannot add to balance, account is closed.");
        }
        currentBalance += amount;
      }
     @Test
      public void diffbluetestAddToBalance() throws AccountException {
        // Arrange
        Account account = new Account(1234567890L, new Client("Carlos Welch"), 10L);
    
        // Act
        account.addToBalance(10L);
    
        // Assert
        assertEquals(20L, account.getCurrentBalance());
      }
    public class VirtualSnackCupboard {
    
      public static Snack whatCanISnackNow(int oClock) {
        if (oClock == 10) {
          return Snack.CHOCOLATE;
        } else if (oClock == 15) {
          return Snack.CAKES;
        } else {
          return Snack.VEGGIE;
        }
      }
      enum Snack {VEGGIE, CHOCOLATE, CAKES}
    }
      public void diffbluetestPickSnack() {
        assertEquals(VirtualSnackCupboard.Snack.CHOCOLATE, VirtualSnackCupboard.whatCanISnackNow(10));
        assertEquals(VirtualSnackCupboard.Snack.CAKES, VirtualSnackCupboard.whatCanISnackNow(15));
        assertEquals(VirtualSnackCupboard.Snack.VEGGIE, VirtualSnackCupboard.whatCanISnackNow(0));
      }
    mvn --batch-mode --no-transfer-progress clean install -DskipTests
      mkdir -p "~/dcover"
      cd "~/dcover"
      curl --silent --show-error --location --output "diffblue-cover-cli.zip" "$DIFFBLUE_COVER_URL"
      unzip -q "diffblue-cover-cli.zip"
      rm -f "diffblue-cover-cli.zip"
      PATH=$PATH:~/dcover/
      dcover activate "$DIFFBLUE_COVER_LICENSE_KEY"
      dcover create --working-directory="moduleToTest" --batch
    INFO  Found 7 callable methods in 2 classes
    INFO
    INFO  Creating tests:
    INFO  ---------------
    ...
    INFO  All 5 created tests were successfully validated.
      dcover create com.somepackage.SomeClass --working-directory="moduleToTest" --batch
      for MODULE in module_name_1 module_name_2 module_name_3
      do
        dcover create --batch --working-directory="$MODULE"
      done
      git config user.name db-ci-bot
      git config user.email [email protected]
      if [ -n "$(git status --short **/*DiffblueTest.java)" ]; then 
        git add **/*DiffblueTest.java
        git commit --message "Update Unit Tests for $(git rev-parse --short HEAD)"
        git push --set-upstream origin
      else
        echo "Nothing to commit"
      fi
    LAST_NON_BOT_COMMIT="$(git rev-list -1 --author='^(?!db-ci-bot).*$' --perl-regexp HEAD --no-merges)"
    LAST_COMMIT="$(git rev-list HEAD -1 --no-merges)"
    if [[ "$LAST_NON_BOT_COMMIT" == "$LAST_COMMIT" ]]
    then
      ...
    fi
    1. Install Diffblue Cover CLI
    1. Download the latest version of Diffblue Cover CLI .exe installer or .zip file: - Download directly here using this link - From your organization's internal file/app store.\

    2. If you use the installer, run the .exe installer and follow the on-screen prompts - during installation you can select where to install Diffblue Cover.

    3. If you use the archive file, extract the .zip file to an appropriate installation folder. Add the install folder path to your PATH environment variable or create a new %DCOVER% environment variable and add that to PATH.

    4. When you're done, restart your PC. Once complete, open Windows PowerShell and enter dcover version to check the install and PATH configuration - if all is OK, Cover will display the current version.

    1. Download the latest version of Diffblue Cover CLI .zip file from: - Download directly - From your organization's internal file/app store.\

    2. Unzip the Cover CLI zip file to an appropriate installation location (for example, ~/bin) and add this location in the PATH environment variable using the following example commands:\

      Reminder: Make sure that the PATH environment variable is set permanently according to your operating system instructions.

    2. Apply a license

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, as well as details of offline licensing (Enterprise Edition only), see Licensing.

    • To activate your license, open Windows PowerShell (Windows) or Terminal (macOS/Linux) and enter the command dcover activate <license-key> - replace <license-key> with the license key provided in your welcome email or provided by your organization.

    • Entering multiple different license keys will overwrite the existing key.

    • You can check your license status by running the command dcover license

    3. Try it out

    Four steps to automatically write tests - check out a few basics, clone an example project, compile the project and check your environment, and finally, one command to write tests - done.

    Step 1 - A few basics

    We won't cover every CLI command option, but here are a few details to get you started:

    Command
    Description

    dcover help

    Help - get, err, help. Use this with the other commands as well to get some details of what options are available (like dcover help create to get details of the available optional arguments).

    dcover activate <license-key>

    Activate License - apply/activate a license. Replace <lic-key> with the license key provided in your welcome email or provided by your organization.

    dcover license

    Check License - display your current license status.

    dcover version

    Check Version - display the version of Diffblue Cover CLI.

    dcover create

    Create Tests - write tests for the project (run from the root directory of the project). You can restrict this further by simply specifying the method or class path - this is detailed a little further in the example in Step 4 below.

    dcover create --<arguments>

    Optional Arguments - there's a few, OK quite a lot. The optional arguments provide access to deeper functionality within Cover CLI such as creating coverage reports, specifying a build configuration file, and running preflight checks (this one is used in Step 3 below).

    Step 2 - Clone the example project Spring PetClinic

    We're going to make use of an example project (Spring PetClinic) to show Diffblue Cover CLI at work. First, we'll clone the project from the Git repo:

    From IntelliJ select File > New... > Project from version control.

    • Ensure Git is selected in Version control.

    • Enter https://github.com/diffblue/demo-spring-petclinic as the URL.

    • Select the directory/folder to clone the project to.

    • When you're ready, click Clone.

    1. Open a command line and navigate to where you want to clone this project.

    2. Run the following command:

    Step 3 - Compile the project and check your environment

    Before we write any tests, we need to compile the PetClinic project. Diffblue Cover works by analyzing the bytecode of any project used with Cover. Open a command line, navigate to the directory containing the PetClinic project, and run the Maven install command:

    Basic prerequisites:

    • Java 8, 11, 17, or 21 compatible source code, or Kotlin source code.

    • Maven 3.2.5+ or Gradle 4.9+ build tools.

    • The project (for use with Diffblue Cover) must compile and run with no failing unit tests.

      JUnit and TestNG testing frameworks are supported.

    • For the best results, your project needs to be completely built from the root.

    More details:

    Diffblue Cover requires that the system environment (hardware, operating system, network connectivity, Java installation) as well as the project environment (build tooling, dependencies, presence of artifacts, existing unit tests) meet the minimum requirements as detailed in Specs & Reqs. Cover CLI will perform an environment check before analysis begins to ensure that the requirements are met - if there are any issues, these will be reported via the Diffblue Cover panel in IntelliJ using E(Environment) Output Codes.

    Further details can be found in the Compiling your project successfully section.

    Check your environment:

    Cover CLI also provides a command line option to run these checks, without writing any tests, useful when you just want to check-out your environment without doing anything else. To run a preflight environment check, open a command line, navigate to the directory containing the PetClinic project, and run the preflight checks:

    Step 4 - Automatically write tests for the example project

    Initially, we'll create tests for the OwnerController class:

    And that's it, simple - 1 command line, 9 methods analyzed, 14 tests written, around 340 lines of code created, and all in around 65 seconds - computationally perfect, human readable. You'll find these tests in:

    demo-spring-petclinic/src/test/java/org/springframework/ samples/petclinic/owner/OwnerControllerDiffblueTest.java

    Once you're happy with this first set of tests, create the full test suite for the entire PetClinic project:

    That's it, two "words" and you're done. Of course this one takes a little longer to complete (approx. 5 minutes) as it creates tests across the entire PetClinic project, analyzing 97 methods and creating 77 tests (exact count may vary slightly). To take a look at the tests, open a xxxDiffblueTest.java file in your IDE of choice (these files are saved to the /src/test/java directory structure by default).

    Note that the examples here use DiffblueTest as the default class name suffix and diffbluetest as the default method name prefix, just to highlight the tests created by Diffblue Cover. To change your suffix and prefix, use the --class-name-template and --method-name-template command arguments - see Cover CLI Commands & Arguments for details.

    More...

    What does Cover CLI do?

    • Diffblue Cover first ensures that your code is compiled and examines each method that Cover will create tests for, including any dependent methods.

    • Cover then creates initial test candidates and uses reinforcement learning to evaluate and adjust the test candidate for each method. This process is repeated until the set of tests that optimize coverage are selected and committed to your code base.

    Next steps

    Now you're up and running with Cover CLI:

    • Have a scan through the Test examples topic which provides some additional source code examples along with an explanation of the tests created by Diffblue Cover.

    • Create some tests for your own project - as long as you have a project that compiles and your environment meets the Cover prerequisites, you're literally a single command line away from AI written tests, created in seconds instead of hours.

    • See Cover CLI to familiarize yourself with the full set of CLI features and functions.

    Diffblue Cover - one AI

    Diffblue Cover is also provided as an IDE plugin tool so you can write tests with one click in the IntelliJ IDE (see Get started - Cover Plugin), and can also be integrated into your CI pipeline to automatically write tests within your CI workflow (see Get started - Cover Pipeline).

    But Cover CLI, Cover Plugin, and Cover Pipeline are not mutually exclusive, in fact they make perfect partners. Use Cover Plugin within the IntelliJ IDE to write and check unit tests for your application during development, and also use Cover CLI directly from the IntelliJ Console or your OS command line to access the wider and deeper functionality provided by Cover CLI - finally, use Cover Pipeline within your CI tool to automate the whole process and provide consistency across your organization.

    Cover CLI
    Update Cover

    Unit Tests - IDE

    Use Diffblue Cover within the IntelliJ IDE to create tests for your methods and classes.

    Unit Tests - CLI

    Use Diffblue Cover from a command line to create tests for your projects.

    Test Coverage

    Create coverage reports and improve test coverage.

    GitHub

    Integrate the Diffblue Cover Action into your GitHub workflows.

    GitLab

    Incorporate the Diffblue Cover Project Integration into your GitLab pipeline.

    Other CI

    Integrate Cover CLI into your CI pipeline workflow - Jenkins, Azure, AWS.

    Admin - IntelliJ

    Install, manage, and maintain Cover Plugin.

    Admin - CLI

    Install, manage, and maintain Cover CLI.

    Admin - Reports

    Install, manage, and maintain Cover Reports.

    Developer

    Generate and upload Cover Reports bundles.

    Senior Developer

    Use Cover Reports to monitor and manage test coverage.

    Administrator

    Manage and maintain your Cover Reports instance.

    Output Codes

    [5 reference topics]

    Reference details - Diffblue Cover output codes, messages, and descriptions.

    Working With Output Codes

    [12 topics]

    Useful hints and tips to help resolve a range of output codes.

    Partial Tests

    [4 min read]

    Creating partial (incomplete) tests.

    Custom Inputs

    [22 min watch]

    Demonstrating how to provide custom inputs to optimize test creation.

    Custom Inputs

    [12 min read]

    Provide custom inputs to optimize test creation.

    Custom Test Setup

    [31 min watch]

    Demonstrating how to provide a custom base class to optimize test creation.

    Custom Test Setup

    [6 min read]

    Provide a custom base class to optimize test creation.

    Test Naming

    [4 min read]

    Test naming config and defaults.

    Test Formatting

    [4 min read]

    Configure the format of tests written by Cover CLI.

    Test Insertion Order

    [2 min read]

    Test method ordering in test classes.

    Refactor

    [4 min read]

    Use Cover Refactor to automatically suggest and apply refactorings to your code to help improve test coverage.

    Cover CLI Admin

    Manage and maintain Cover CLI.

    Test Coverage

    Improve and manage test coverage.

    Tutorials

    A range of tutorials covering topics such as implementing a code change and working with Kotlin projects.

    Get started - Cover Plugin

    Get started with Diffblue Cover Plugin for IntelliJ - in short, install the plugin, apply your license, and you're ready to go. This topic also provides an example and some next steps.

    If you've already done this as part of your free trial, you may want to skip this and jump straight to the Cover Plugin details, or perhaps you want to update to the latest version - see Update Cover.

    eLearning

    Short on time? If you'd like a fast-track experience check out our getting started video. [5 min]

    1. Install Diffblue Cover Plugin for IntelliJ

    1. In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).

    2. Select the Marketplace tab, search for Diffblue, and click Install. Your plugin will now be downloaded and installed.

    2. Apply a license

    Once IntelliJ has restarted, you'll be prompted for your license key (provided in your welcome email or by your organization) to activate the plugin. Alternatively, the license can be activated at any time from the IntelliJ toolbar Diffblue > Activate License. Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, see . Note that:

    • Applying a license provides access to the Teams and Enterprise Editions of Diffblue Cover.

    • Cover Plugin Community Edition is free to use but does require product verification to activate your perpetual license.

    • Offline license activation is available with the Diffblue Cover Enterprise Edition only. This can only be done through the CLI.

    • See and for more details.

    3. Try it out

    Four steps to automatically write tests - clone an example project, compile the project and check your environment, learn a few basics, and then one click or one command to write tests.

    Step 1 - Clone the example project Spring PetClinic

    We're going to make use of an example project (Spring PetClinic) to show the Diffblue Cover Plugin for IntelliJ at work. First, we'll clone the project from the Git repo:

    1. Open a command line and navigate to where you want to clone this project.

    2. Run the following commands:

    1. Open the PetClinic project in IntelliJ.

    From IntelliJ select File > New... > Project from version control.

    Step 2 - Compile the project and check your environment

    Before we write any tests, we need to compile the PetClinic project. Diffblue Cover works by analyzing the bytecode of any project used with Cover. You can do this from the Maven plugin in IntelliJ - click the Maven tab, open petclinic > Lifecycle, and double-click package.

    Basic prerequisites:

    • Java 8, 11, 17, or 21 compatible source code, or Kotlin source code.

    • Maven 3.2.5+ or Gradle 4.9+ build tools.

    • The project (for use with Diffblue Cover) must compile and run with no failing unit tests.

      JUnit and TestNG testing frameworks are supported.

    More details:

    Diffblue Cover requires that the system environment (hardware, operating system, network connectivity, Java installation) as well as the project environment (build tooling, dependencies, presence of artifacts, existing unit tests) meet the minimum requirements as detailed in . Cover Plugin will perform an environment check before analysis begins to ensure that the requirements are met - if there are any issues, these will be reported via the Diffblue Cover panel in IntelliJ using E (Environment) .

    Note that you can run dcover create --preflight (using ) to check the Cover prerequisites for your project, without performing any other actions.

    Step 3 - A couple of basics

    We won't cover the whole UI here, but here are a few useful gutter icons to get you started:

    Icon
    Description

    Step 4 - Automatically write tests for the example project

    1. Navigate to a class - for example, OwnerController.

    2. To create tests for this class, click on the Write Tests gutter icon next to the line class OwnerController.

    3. Click the links in the Diffblue Cover panel to see the tests produced - example below.

    And that's it, simple - 1 click, 9 methods analyzed, 7 tests written, around 340 lines of code, and all in around 65 seconds - computationally perfect, human readable.

    Note that the examples here use DiffblueTest as the default class name suffix and diffbluetest as the default method name prefix, just to highlight the tests created by Diffblue Cover. To change your suffix and prefix in IntelliJ, go to Diffblue > Change Settings > Test Naming > Class Template/Method Template.

    More...

    What does the plugin do?

    • Diffblue Cover first ensures that your code is compiled and examines each method that Cover will create tests for, including any dependent methods.

    • Cover then creates initial test candidates and uses reinforcement learning to evaluate and adjust the test candidate for each method. This process is repeated until the set of tests that optimize coverage are selected and committed to your code base.

    More tests

    This simple "getting started" example illustrates creating tests for a class using the gutter icons (you can do the same for individual methods too). You can scale this up even further - right-click a Java source file or folder in your project structure and select Write Tests to create tests for all classes/methods contained within the file/folder. Of course that may not always be desirable:

    • A large project with potentially a large number of tests can take some time to complete.

    • License limits may apply.

    Next steps

    Now you're up and running with Cover Plugin:

    • Have a scan through the topic which provides some additional source code examples along with an explanation of the tests created by Diffblue Cover.

    • Create some tests for your own project - as long as you have a project that compiles and your environment meets the Cover , you're literally a click away from AI written tests, created in seconds instead of hours.

    • Select your own preferences/settings for Cover Plugin - go to Diffblue > Change Settings.

    Diffblue Cover - one AI

    Diffblue Cover is also provided as a CLI tool to write tests for your entire project, all in one hit (see ), and can also be integrated into your CI pipeline to automatically write tests within your CI workflow (see ).

    But Cover CLI, Cover Plugin, and Cover Pipeline are not mutually exclusive, in fact they make perfect partners. Use Cover Plugin within the IntelliJ IDE to write and check unit tests for your application during development, and also use Cover CLI directly from the IntelliJ Console or your OS command line to access the wider and deeper functionality provided by Cover CLI - finally, use Cover Pipeline within your CI tool to automate the whole process and provide consistency across your organization.

    cd demo-spring-petclinic
    ./mvnw install
    cd demo-spring-petclinic
    dcover create --preflight
    dcover create org.springframework.samples.petclinic.owner.OwnerController
    package org.springframework.samples.petclinic.owner;
    
    import ...
    
    @ContextConfiguration(classes = {OwnerController.class})
    @ExtendWith(SpringExtension.class)
    class OwnerControllerDiffblueTest {
    	@Autowired
    	private OwnerController ownerController;
    
    	@MockBean
    	private OwnerRepository ownerRepository;
    
    	/**
    	 * Method under test: {@link OwnerController#initCreationForm(Map)}
    	 */
    	@Test
    	void diffbluetestInitCreationForm() throws Exception {
    		MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/owners/new");
    		MockMvcBuilders.standaloneSetup(ownerController)
    			.build()
    			.perform(requestBuilder)
    			.andExpect(MockMvcResultMatchers.status().isOk())
    			.andExpect(MockMvcResultMatchers.model().size(1))
    			.andExpect(MockMvcResultMatchers.model().attributeExists("owner"))
    			.andExpect(MockMvcResultMatchers.view().name("owners/createOrUpdateOwnerForm"))
    			.andExpect(MockMvcResultMatchers.forwardedUrl("owners/createOrUpdateOwnerForm"));
    	}
    
    ....
    dcover create

    Once complete, run dcover version to check the install and PATH configuration - if all is OK, Cover will display the current version.

    here using this link
    mkdir ~/bin
    cd ~/bin
    unzip ~/diffblue-cover*.zip
    export PATH=$PATH:~/bin
    git clone https://github.com/diffblue/demo-spring-petclinic

    When prompted, click Restart IDE to complete the install.

    1. Download the Diffblue Cover Plugin for IntelliJ as a .zip bundle from: &#xNAN;- The Diffblue website - Free Community Edition or Free Trial versions. &#xNAN;- The JetBrains Marketplace (IntelliJ Plugin Marketplace). &#xNAN;- The link sent to you via your Diffblue Cover welcome email. &#xNAN;- Your organization's internal file/app store.\

    2. In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).

    3. Click on the cog icon next to the Installed tab and select Install Plugin from Disk.... Navigate to the location of the plugin, select the zip file, and click OK.

    4. When prompted, click Restart IDE to complete the install.

  • Ensure Git is selected in Version control.

  • Enter https://github.com/diffblue/demo-spring-petclinic as the URL.

  • Select the directory/folder to clone the project to.

  • When you're ready, click Clone.

  • See Cover Plugin to familiarize yourself with the full set of plugin features and functions.

    Write tests - click this icon to write tests for this method or class.

    Not testable - this method or class can't be tested. Click the icon to find out why.

    Private method - this method can't be tested as it's private, although it may be tested indirectly via a public method. If you'd like Cover to write unit tests for this method, you can either make the method public or package protected.

    Test maintenance - displayed next to test classes and methods in project test files. Click the icon to update or delete tests for the method or class.

    Delete test - displayed next to your test methods in project test files. Click the icon to delete a test method.

    Licensing
    Cover Editions
    Licensing
    Specs & Reqs
    Output Codes
    Diffblue Cover CLI
    Test examples
    prerequisites
    Get started - Cover CLI
    Get started - Cover Pipeline

    Customizing test setup

    By default, Diffblue Cover will write tests that are executed in isolation but it's possible to provide a custom base class with additional logic to run before / after the tests themselves.

    Background

    A key feature of Diffblue Cover is automatically configuring classes such that the method under test can be successfully executed.

    However, sometimes Diffblue Cover is unable to appropriately configure and clean up the environment such that tests can be usefully written and needs guidance from the user in the form of a custom base class which can provide behavior inherited by the test class.

    eLearning

    Custom Base Class

    When writing tests for com.example.SomeClass Diffblue Cover will look for the existence of com.example.SomeClassDiffblueBase and use that as a super-class when writing com.example.SomeClassDiffblueTest. This com.example.SomeClassDiffblueBase class can contain methods to be run before/after writing tests, correctly annotated according to the testing framework used. The base class needs to have the same name as the class under test, with a DiffblueBase suffix appended, it must be in the same package as the class under test, but likely should be defined in the src/test/java source tree so that it’s kept separate from production code.

    Note that if you're creating tests with TestNG for a class that uses Spring, the custom base class feature cannot be used.

    Given a class under test: src/main/java/com/example/SomeClass.java

    and a custom base class: src/test/java/com/example/SomeClassDiffblueBase.java

    then Cover will write a test class src/test/java/com/example/SomeClassDiffblueTest.java extending that custom base class.

    Note: Once the custom base class has been written or updated, please make sure that it has been compiled so that Cover is able to find the compiled class.

    @BeforeXXX Annotated Methods

    The most common use case for using a custom base class is to customize the test setup, often to perform some static initialization of some environmental state.

    For example, your base class might need to switch to some test environment before tests are run at all, and might need to reset some license limits ahead of each test run.

    If your class under test needs some shared environment state to be set up before tests are run at all, you can add a static, visible, no-argument method to your base class annotated with org.junit.jupiter.api.BeforeAll (or org.junit.BeforeClass if using JUnit 4, respectively org.testng.annotations.BeforeClass if using TestNG) performing that initialization logic.

    If your methods under test need some state setup or reset before each test is run, you can add a non-static, visible, no-argument method to your base class annotated with org.junit.jupiter.api.BeforeEach (or org.junit.Before if using JUnit 4, respectively org.testng.annotations.BeforeMethod if using TestNG) performing that initialization logic.

    For example, your base class might look like the following, with setupTestEnvironment() being called once before SomeClassDiffblueTest, and resetLicenseLimits() being called before each test method found:

    @AfterXXX Annotated Methods

    A less common use case for a custom base class is to customize the test cleanup logic.

    If your class under test needs some shared environment state to be cleared after tests are all run, you can add a static, visible, no-argument method to your base class annotated with org.junit.jupiter.api.AfterAll (or org.junit.AfterClass if using JUnit 4, respectively org.testng.annotations.AfterClass if using TestNG) performing that logic.

    If your method under test needs some state reset after each test is run, you can add a non-static, visible, no-argument method to your base class annotated with org.junit.jupiter.api.AfterEach (or org.junit.After if using JUnit 4, respectively org.testng.annotations.AfterMethod if using TestNG) performing that logic.

    For example, your base class might look like the following, with resetLicenseUsageCount() being called after each test in SomeClassDiffblueTest and then resetTestEnvironment() called after all the tests:

    Field Inputs

    Another use case for custom base classes is to provide initialized inputs that Cover would otherwise struggle to get right.

    For example, perhaps your method under test requires some ComplexObject in order to execute, but it requires multiple calls to configure.

    Note: Currently only static fields can be used.

    Given a class under test: src/main/java/com/example/SomeClass.java

    and a custom base class: src/test/java/com/example/SomeClassDiffblueBase.java

    Cover will use that initialized field to write the test class: src/test/java/com/example/SomeClassDiffblueTest.java

    Just the basics

    Just need to know the basics? You've come to the right place.

    Start here...

    Next steps...

    Module 1: Create your Cover unit test baseline

    In this module, we will enable you to perform the first steps of onboarding a new project. These are:

    1. make your first projects Cover-ready by validating the build configuration with respect to unit testing, and

    2. write a test baseline for your first projects

    Diffblue Sandbox

    Diffblue Cover writes unit tests by running your code thousands of times as it searches for the best tests that achieve maximum coverage and regression detection. By default, your code is run inside a sandbox which blocks calls with potentially disruptive side-effects such as network, file system, or system changes. However, this can also limit the number of tests that Diffblue Cover can write. Disabling the Diffblue sandbox will allow Cover to run all of your code regardless of side-effects, thereby maximizing coverage. Disabling the sandbox must be done with caution as your code may behave in ways you don't expect (e.g. file system modifications).

    Note that if you receive the output code R011 when using Diffblue Cover, this means the method tested performs operations that violate Diffblue Cover’s sandbox policy.

    Sandbox Policy

    git clone https://github.com/diffblue/demo-spring-petclinic
    package org.springframework.samples.petclinic.owner;
    
    import ...
    
    @ContextConfiguration(classes = {OwnerController.class})
    @ExtendWith(SpringExtension.class)
    class OwnerControllerDiffblueTest {
    	@Autowired
    	private OwnerController ownerController;
    
    	@MockBean
    	private OwnerRepository ownerRepository;
    
    	/**
    	 * Method under test: {@link OwnerController#initCreationForm(Map)}
    	 */
    	@Test
    	void diffbluetestInitCreationForm() throws Exception {
    		MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/owners/new");
    		MockMvcBuilders.standaloneSetup(ownerController)
    			.build()
    			.perform(requestBuilder)
    			.andExpect(MockMvcResultMatchers.status().isOk())
    			.andExpect(MockMvcResultMatchers.model().size(1))
    			.andExpect(MockMvcResultMatchers.model().attributeExists("owner"))
    			.andExpect(MockMvcResultMatchers.view().name("owners/createOrUpdateOwnerForm"))
    			.andExpect(MockMvcResultMatchers.forwardedUrl("owners/createOrUpdateOwnerForm"));
    	}
    
    ....
    Prerequisites

    To start this module, you need to satisfy the prerequisites, which amount to having Cover installed at least to the level of Reference Deployment 1, i.e.

    • Cover Reports is installed on a central server.

    • As a champion you have Cover CLI installed in a development environment that satisfies the requirements.

    • You have run preflight and sent the log files to Diffblue.

    License activation

    Activate Cover CLI using the license key that you received from the contact for software and license distribution in your organization:

    View your license details to check that the activation was successful:

    Telemetry configuration

    We will check that telemetry is correctly configured on your system.

    Usage information is sent to

    • External Diffblue telemetry server (Enterprise Edition users can opt out)

    • Cover Reports (if configured)

    Telemetry is configured via one of

    • ~/.diffblue/telemetry.properties, or

    • Environment variables

    Check that:

    • External telemetry is configured according to your company policies.

    • Cover Reports telemetry points to your central Cover Reports server.

    Make your project Cover-ready

    We will work through the whole flow for creating baseline tests.

    You can find a worked example of the entire flow here.

    If your project has multiple modules we recommend that you start with a representative module. Once the selected module is working, repeat the steps on the other modules.

    Note that you can run a specific module without changing your working directory by adding the following option to the dcover commands: --working-directory your-selected-module

    We will start with the validation of your build configuration - and fixing it if necessary. We will also measure and upload your existing unit test coverage.

    Step
    Command

    1. Build the project from its root

    E.g. ./mvnw install -DskipTests

    2. Check and fix the project environment

    dcover create

    dcover

    If necessary, apply manual fixes to your build configuration

    3. Commit fixes

    As soon as preflight doesn't report any errors or warnings:

    git checkout -b diffblue-baseline

    git commit -a -m "Build configuration fixes for Diffblue"

    4. Measure and upload existing coverage

    dcover

    dcover http://your-cover-reports:8080

    View Cover Reports

    Create your unit test baseline

    We are now ready to create the baseline tests.

    Step
    Command

    5. Create the baseline tests and measure coverage

    dcover

    6. Commit the baseline tests

    git add `find . -name '*DiffblueTest.java'`

    git commit -m "Diffblue baseline tests"

    7. Upload the baseline coverage

    dcover http://your-cover-reports:8080

    8. Review results

    View Cover Reports

    View created tests in IntelliJ

    9. Push the changes

    git push --set-upstream origin diffblue-baseline

    Create a pull request and get it merged.

    What does Cover CLI do?

    When running a Cover command, the execution proceeds in several phases.

    Phase
    Description
    Additional execution information

    Detecting environment

    Every Cover command starts by performing environment health checks to detect whether the project environment is ready for the Cover command to run.

    When using , Cover stops after this phase and outputs an environment summary.

    Creating tests

    This phase performs the generation of tests class per class, method per method.

    Only executed when using the command.

    Ends with a summary with number of tests created and issues encountered.

    Validating tests

    This phase validates the created tests, i.e. it removes non-compiling and failing tests.

    Executed after test generation when using the command.

    Test validation can also be run separately using the command.

    Calculating coverage

    This phase calculates the coverage of manually written and Diffblue tests using JaCoCo.

    Understanding Cover's log output

    Cover produces output with increasing degree of detail:

    • Console output

    • Console output with --verbose

    • User log file

    • Support log file

    The log files are in the .diffblue/log directory below the directory from where Cover was run.

    Overview of CLI options

    The following is a short list of the more pertinent options for creating baseline tests. Details of additional options can be found in the Commands & Arguments.

    • Select module to run on without changing directory, e.g. --working-directory my-module/my-submodule

    • Exclude modules, e.g. --exclude-modules my-module/to-exclude

    • Verbose console output: --verbose

    • Prefer Maven over Gradle:

    • Test framework, e.g. junit-4

    • Active Spring profiles, e.g. test

    • Ignore style checks:

    • System properties, e.g. my.property=value

    • Environment variables, e.g. MYVAR=value

    • CLI help: dcover help create

    Cover automatically figures out which entry point methods to write tests for. The set of methods can be restricted by specifying inclusions and exclusions. E.g. to write tests only for the OwnerController class you can run dcover create org.springframework.samples.petclinic.owner.OwnerController

    What does Cover do during test generation?

    To generate tests, Cover analyzes your project's bytecode. It runs your code, and thus operates in a sandbox. The sandbox runs in a separate service process which prohibits system calls (file system, network, etc) to protect your system from potentially detrimental functionality within your codebase (e.g. wiping your filesystem, spamming third party services).

    Cover partitions your code into groups of methods under test that it is going to test. For each group of methods under test, Cover

    • either produces tests

    • or an output code that explains why it didn’t produce complete tests

    Understanding Cover's output codes

    Output codes identify the messages that Cover outputs, e.g. E052 - Missing dependency

    The output code can be used to quickly look it up in docs: e.g. https://diff.blue/E052

    There are different types of messages distinguished by the first letter in the output code:

    • Informational messages:

      • Testability (T), reason for not writing tests (R)

    • Warnings/errors:

      • Project environment (E) including coverage measurement and reports upload

      • Licensing (L)

    What does test validation do?

    Validation ensures that generated tests compile and pass. This is essential for Cover's autonomous operation in your CI Pipeline.

    You may see two output codes related to test validation:

    • First, tests are compiled and run individually (W output code).

    • Finally, tests are run via your build system (V output code).

    Coverage measurement

    Cover uses JaCoCo for coverage measurement.

    Cover distinguishes two types of tests:

    • Diffblue-controlled tests (“Diffblue”)

      • Unchanged tests written by Cover

      • Automatically maintained by CI pipeline

    • User-controlled tests (“manual”)

      • Manually written or modified Diffblue tests

      • Maintained by user

      • These include the existing tests that you have manually written before starting to use Cover.

    How to ask for support

    Before reaching out, check for potential solutions in

    • the documentation

    • and the forum

    More complex questions & issues contact support depending on your support plan.

    Requirements for Diffblue to handle your support case:

    • Detailed description of what you did and the behavior you observe (compared with what you expect)

      • Diffblue Cover support log file

      • Additionally, for R code-related questions, one of the following:

        • A reproducer (most valuable to be able to support): a piece of code that results in the the R code message that you see

        • A code snippet of the relevant code under test (useful, but with lower chances of success) and a (if there is one) with the R code

    Worked example: Baseline creation process using the Petclinic demo project

    The prerequisites for running this example are:

    • JDK 17 has been installed.

    • Cover Reports has been downloaded, unpacked locally, and started by running bin/cover-reports

    • The demo project has been cloned by running git clone https://github.com/diffblue/demo-spring-petclinic

    • To use the dcover fix-build command in step 2, must be met.

    We will work through the whole flow for creating baseline tests.

    Step
    Command

    1. Build the project from its root

    ./mvnw install -DskipTests

    2. Check and fix the project environment

    dcover create --preflight

    dcover fix-build

    3. Commit fixes

    git checkout -b diffblue-baseline

    git commit -a -m "Build configuration fixes for Diffblue"

    4. Measure and upload existing coverage

    dcover coverage-reports

    dcover upload http://localhost:8080

    5. Create the baseline tests and measure coverage

    dcover create --coverage-reports

    6. Commit the baseline tests

    git add `find . -name '*DiffblueTest.java'`

    git commit -m "Diffblue baseline tests"

    Sandbox Policy Disabled (Changes Highlighted)

    Allow access to reflective Java operations (e.g. getting the list of methods of a class).

    Allow access to reflective Java operations (e.g. getting the list of methods of a class).

    Allow setting properties (JUnit needs this during test execution).

    Allow setting properties (JUnit needs this during test execution).

    Allow creating classloaders.

    Allow creating classloaders.

    Allow reads of all files.

    Allow reads of all files.

    Allow writes to files created in this session (including deletion).

    Allow writes of all files (including deletion).

    Allow writes of files in java.io.tmpdir (including deletion).

    Allow writes of all files (including deletion).

    Deny writes of files, not created in this session and outside of java.io.tmpdir (including deletion).

    Allow writes of all files (including deletion).

    Deny URL accesses (unless it's a file:// url with a GET request, in which case it's treated like a regular file operation).

    Allow URL accesses.

    Deny retrieving network information.

    Allow retrieving network information.

    Deny creating Sockets.

    Allow creating Sockets.

    Deny GUI access.

    Allow GUI access.

    Deny sun.misc.Unsafe/sun.misc.*

    Allow sun.misc.Unsafe/sun.misc.*

    Deny external process accesses.

    Allow external process accesses.

    Deny Java Management Extensions (JMX) access.

    Allow Java Management Extensions (JMX) access.

    Deny Java Native Interface (JNI) access.

    Allow Java Native Interface (JNI) access.

    Deny Smartcards (java.smartcardio.*).

    Allow Smartcards (java.smartcardio.*).

    Deny Printers (javax.print.*).

    Allow Printers (javax.print.*).

    Deny setting the security manager.

    Allow setting the security manager.

    Deny access control context.

    Allow access control context.

    Deny Kerberos Authentication access.

    Allow Kerberos Authentication access.

    Deny System.exit calls.

    Deny System.exit calls.

    Disabling the Diffblue Sandbox

    The sandbox policy can be disabled to allow almost all of the operations outlined above (except calling System.exit). However, we recommend that you fully familiarize yourself with the information contained in this topic in order to avoid any undesirable effects by allowing these previously denied operations.

    To disable the sandbox policy, go to Diffblue > Change Settings > Sandboxed Environment in IntelliJ and uncheck Enable sandboxing.

    Note that if you just want to allow a small set of JNI libraries, use the JNI allow list (a comma separated list of JNI library name prefixes) - go to Diffblue > Change Settings > Sandboxed Environment > Allowed JNI prefixes.

    Also, you may want to consider simply refactoring parts of your code. For example, if you have a method that executes a denied operation but also contains business logic that needs to be verified, you could refactor your code so that any logic that can be executed within the sandbox is contained in a separate, unit-testable method - this ensures the business logic is tested and consequently increases code coverage.

    Harmful Example

    Let's look at an example of a denied operation and what could happen if it were allowed. One of the operations prevented by default is accessing files outside of the temp directory (specified by java.io.tmpdir). We further restrict this by allowing only writing to newly created files. The root parameter may end up pointing to a real directory on your system (it could be given any value, such as /, C:\, /home/User/), and then be executed, removing all the files contained within that directory along with the directory itself. With the default policy in place, trying to write tests for this method would result in an R011 output code.

    Operations

    The tables below outline the denied operations (Diffblue sandbox enabled) and explains what can happen (in the worst case) if they are allowed (Diffblue sandbox disabled). Note that:

    • The exact nature of the risk is heavily dependent on the application being analyzed and can't be predicted ahead of time. If the application being analyzed is a web-based application in an automated pipeline that has no access to production systems, the risk of experiencing many of the adverse effects mentioned below is relatively low.

    • The impact of the Diffblue sandbox policy is not restricted to just the method, but methods that call these methods, and so on.

    I/O Operation

    Operation
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed

    Networking

    No

    Allowed

    Unexpected network traffic, data loss on remote machines, instability in unit tests.

    FileIO

    Read all files, write new files.

    Read all files, write all files.

    Data loss on the machine where Cover is running, instability in unit tests.

    TmpFileIO

    Read all files, write new files.

    • Data loss is likely to occur if methods (like a hypothetical delete method in a typical web application) are invoked and happen to have access to live credentials (e.g. production or test environments).

    • Likewise, unexpected network traffic can occur if the application makes raw network requests to servers.

    • Disk space may be consumed because the application may not clean up temporary files.

    Java Libraries

    Library
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed

    GUI (Swing/AWT)

    No, java.awt.headless is set to true

    Allowed, java.awt.headless is set to false

    N/A

    sun.misc.*

    No

    Allowed

    Instability of tests across JVM vendors and operating systems.

    sun.misc.Unsafe

    No

    • Trying to write unit tests for methods that invoke GUIs is difficult. In those cases, the java.awt.headless property is usually set to true to disable those GUI components. If you require tests for the logic behind the GUIs, it's better to refactor the code to allow that logic to be tested independently of the GUI.

    • The sun.misc.* packages provide very low level access to fundamental system operations and do not form a part of the public interface. Because of the very low level access, we deem these operations unsafe due to the risk of unintended side effects.

    • Furthermore, the following is taken from the published Oracle regarding the use of these packages.

    The sun.* packages are not part of the supported, public interface.

    A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.

    Each company that implements the Java platform will do so in their own private way. The classes in sun.* are present in the JDK to support Oracle's implementation of the Java platform: the sun.* classes are what make the Java platform classes work "under the covers" for Oracle's JDK. These classes will not in general be present on another vendor's Java platform. If your Java program asks for a class "sun.package.Foo" by name, it may fail with ClassNotFoundError, and you will have lost a major advantage of developing in Java.

    Technically, nothing prevents your program from calling into sun.* by name. From one release to another, these classes may be removed, or they may be moved from one package to another, and it's fairly likely that their interface (method names and signatures) will change. (From Oracle's point of view, since we are committed to maintaining the Java platform, we need to be able to change sun.* to refine and enhance the platform.) In this case, even if you are willing to run only on Oracle's implementation, you run the risk of a new version of the implementation breaking your program.

    In general, writing java programs that rely on sun.* is risky: those classes are not portable, and are not supported.

    System Operations

    Operation
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed

    External Processes

    No

    Allowed

    Instability of unit tests, random behavior of other processes.

    JMX

    No

    Allowed

    Instability of unit tests, random behavior of JMX enabled beans/services/etc.

    JNI

    No, except JNI allow list - see below.

    * Note that if the Diffblue sandbox policy is blocking access to a JNI library that you believe to be safe to use, then you can add it to the JNI allow list (a comma separated list of JNI library name prefixes can be used) - go to Diffblue > Change Settings > Sandboxed Environment > Allowed JNI prefixes.

    Peripherals

    Generally, these operations require access to specific hardware which may or may not be present. Because this can't be determined beforehand, unit tests for methods using these APIs would be inherently unstable.

    Peripheral
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed

    Smartcards

    No

    Allowed

    Corruption of data on the smartcards.

    Printing

    No

    Allowed

    Print jobs are submitted to configured printers.

    Security

    Security
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed

    Setting security manager

    No

    Allowed

    Unit tests won't be created or verified.

    Create access control context

    No

    Allowed

    Attempts to bypass sandbox will be allowed.

    Kerberos Authentication

    No

    Sandbox Policy Enabled (Default)

    What is Diffblue Cover

    [8 min read]

    An introduction and overview of Diffblue Cover including features, benefits, and how it works.

    Cover Editions

    [2 min read]

    A summary of features and restrictions for each Diffblue Cover Edition.

    Specs & Reqs

    [reference topic]

    Reference details - specifications and requirements.

    Writing Tests - IDE

    [2 min read]

    A summary of how to write tests using Cover Plugin in IntelliJ.

    Writing Tests - Command Line

    [2 min read]

    A summary of how to write tests from a command line.

    GitHub Actions - Intro

    [3 min watch]

    Introducing Cover Pipeline for GitHub - Diffblue's GitHub Actions workflow.

    GitHub Actions - Overview

    [2 min read]

    An overview of Cover Pipeline for GitHub - Diffblue's GitHub Actions workflow.

    GitLab Integration - Intro

    [4 min watch]

    Introducing Cover Pipeline for GitLab - Diffblue's GitLab project integration.

    GitLab Integration - Overview

    [2 min read]

    An overview of Cover Pipeline for GitHub - Diffblue's GitLab project integration.

    Diffblue Cover Free Trial

    [7 min watch]

    Sit back and watch while we demonstrate the Diffblue Cover free trial.

    Diffblue Cover Free Trial

    [learning path]

    Go beyond the demo and try it out for yourself - our full free trial learning path.

    Diffblue Sandbox

    Diffblue Cover writes unit tests by running your code thousands of times as it searches for the best tests that achieve maximum coverage and regression detection. By default, your code is run inside a sandbox which blocks calls with potentially disruptive side-effects such as network, file system, or system changes. However, this can also limit the number of tests that Diffblue Cover can write. Disabling the Diffblue sandbox will allow Cover to run all of your code regardless of side-effects, thereby maximizing coverage. Disabling the sandbox must be done with caution as your code may behave in ways you don't expect (e.g. file system modifications).

    Note that if you receive the output code R011 when using Diffblue Cover, this means the method tested performs operations that violate Diffblue Cover’s sandbox policy.

    Sandbox Policy

    Disabling the Diffblue Sandbox

    The sandbox policy can be disabled to allow almost all of the operations outlined above (except calling System.exit). However, we recommend that you fully familiarize yourself with the information contained in this topic in order to avoid any undesirable effects by allowing these previously denied operations.

    To disable the sandbox policy, use the --disable-sandbox option.

    Note that if you just want to allow a small set of JNI libraries, use the JNI allow list (a comma separated list of JNI library name prefixes) - specified using the --allow-jni=<value>[,<value>...] argument.

    Also, you may want to consider simply refactoring parts of your code. For example, if you have a method that executes a denied operation but also contains business logic that needs to be verified, you could refactor your code so that any logic that can be executed within the sandbox is contained in a separate, unit-testable method - this ensures the business logic is tested and consequently increases code coverage.

    Harmful Example

    Let's look at an example of a denied operation and what could happen if it were allowed. One of the operations prevented by default is accessing files outside of the temp directory (specified by java.io.tmpdir). We further restrict this by allowing only writing to newly created files. The root parameter may end up pointing to a real directory on your system (it could be given any value, such as /, C:\, /home/User/), and then be executed, removing all the files contained within that directory along with the directory itself. With the default policy in place, trying to write tests for this method would result in an output code.

    Operations

    The tables below outline the denied operations (Diffblue sandbox enabled) and explains what can happen (in the worst case) if they are allowed (Diffblue sandbox disabled). Note that:

    • The exact nature of the risk is heavily dependent on the application being analyzed and can't be predicted ahead of time. If the application being analyzed is a web-based application in an automated pipeline that has no access to production systems, the risk of experiencing many of the adverse effects mentioned below is relatively low.

    • The impact of the Diffblue sandbox policy is not restricted to just the method, but methods that call these methods, and so on.

    I/O Operation

    Operation
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed
    • Data loss is likely to occur if methods (like a hypothetical delete method in a typical web application) are invoked and happen to have access to live credentials (e.g. production or test environments).

    • Likewise, unexpected network traffic can occur if the application makes raw network requests to servers.

    • Disk space may be consumed because the application may not clean up temporary files.

    Java Libraries

    Library
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed
    • Trying to write unit tests for methods that invoke GUIs is difficult. In those cases, the java.awt.headless property is usually set to true to disable those GUI components. If you require tests for the logic behind the GUIs, it's better to refactor the code to allow that logic to be tested independently of the GUI.

    • The sun.misc.* packages provide very low level access to fundamental system operations and do not form a part of the public interface. Because of the very low level access, we deem these operations unsafe due to the risk of unintended side effects.

    • Furthermore, the following is taken from the published Oracle

    The sun.* packages are not part of the supported, public interface.

    A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.

    Each company that implements the Java platform will do so in their own private way. The classes in sun.* are present in the JDK to support Oracle's implementation of the Java platform: the sun.* classes are what make the Java platform classes work "under the covers" for Oracle's JDK. These classes will not in general be present on another vendor's Java platform. If your Java program asks for a class "sun.package.Foo" by name, it may fail with ClassNotFoundError, and you will have lost a major advantage of developing in Java.

    Technically, nothing prevents your program from calling into sun.*

    System Operations

    Operation
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed

    * Note that if the Diffblue sandbox policy is blocking access to a JNI library that you believe to be safe to use, then you can add it to the JNI allow list (a comma separated list of JNI library name prefixes can be used):

    • Cover CLI: Use the --allow-jni option - see and/or for more information.

    • Cover Plugin: Go to Diffblue > Change Settings > Sandboxed Environment > Allowed JNI prefixes.

    Peripherals

    Generally, these operations require access to specific hardware which may or may not be present. Because this can't be determined beforehand, unit tests for methods using these APIs would be inherently unstable.

    Peripheral
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed

    Security

    Security
    Allowed by Default?
    Change with "Disable Sandbox"
    Possible Effect if Allowed
    dcover activate XXXX-XXXX-XXXX-XXXX
    dcover license
    public class Harmful {
        public void deleteRecursively(final Path root) {
            final File[] contents = directoryToBeDeleted.listFiles();
            if (contents != null) {
                for (final File file : contents) {
                    deleteRecursively(file);
                }
            }
            return directoryToBeDeleted.delete();
        }
    }
    package com.example;
    
    class SomeClass {
      void methodUnderTest() {
        // ...
      }
    }
    package com.example;
    
    class SomeClassDiffblueBase {
    
    }
    package com.example;
    
    import org.junit.Test;
    
    class SomeClassDiffblueTest extends SomeClassDiffblueBase {
      @Test
      void testMethodUnderTest() {
        // Arrange
        // ...
    
        // Act
        // ...
    
        // Assert
        // ...
      }
    }
    package com.example;
    
    import org.junit.jupiter.api.Test;
    
    class SomeClassDiffblueTest extends SomeClassDiffblueBase {
      @Test
      void testMethodUnderTest() {
        // Arrange
        // ...
    
        // Act
        // ...
    
        // Assert
        // ...
      }
    }
    package com.example;
    
    import org.testng.annotations.Test;
    
    class SomeClassDiffblueTest extends SomeClassDiffblueBase {
      @Test
      void testMethodUnderTest() {
        // Arrange
        // ...
    
        // Act
        // ...
    
        // Assert
        // ...
      }
    }
    package com.example;
    
    import org.junit.BeforeClass;
    import org.junit.Before;
    
    class SomeClassDiffblueBase {
    
      @BeforeClass
      public static void setupTestEnvironment() {
        // custom static configuration
        Environment.state = new TestEnvironment();
      }
    
      @Before
      public void resetLicenseLimits() {
        // reset license limits
        Licensing.remainingUsages = 100;
      }
    }
    package com.example;
    
    import org.junit.jupiter.api.BeforeAll;
    import org.junit.jupiter.api.BeforeEach;
    
    class SomeClassDiffblueBase {
    
      @BeforeAll
      static void setupTestEnvironment() {
        // custom static configuration
        Environment.state = new TestEnvironment();
      }
    
      @BeforeEach
      void resetLicenseLimits() {
        // reset license limits
        Licensing.remainingUsages = 100;
      }
    }
    package com.example;
    
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.BeforeMethod;
    
    class SomeClassDiffblueBase {
    
      @BeforeClass
      public void setupTestEnvironment() {
        // custom static configuration
        Environment.state = new TestEnvironment();
      }
    
      @BeforeMethod
      public void resetLicenseLimits() {
        // reset license limits
        Licensing.remainingUsages = 100;
      }
    }
    package com.example;
    
    import org.junit.AfterClass;
    import org.junit.After;
    
    class SomeClassDiffblueBase {
    
      @AfterClass
      public static void resetTestEnvironment() {
        // clear test configuration
        Environment.state = null;
      }
    
      @After
      public void resetLicenseUsageCount() {
        // reset license limits
        Licensing.usageCount = 0;
      }
    }
    package com.example;
    
    import org.junit.jupiter.api.AfterAll;
    import org.junit.jupiter.api.AfterEach;
    
    class SomeClassDiffblueBase {
    
      @AfterAll
      static void resetTestEnvironment() {
        // clear test configuration
        Environment.state = null;
      }
    
      @AfterEach
      void resetLicenseUsageCount() {
        // reset license limits
        Licensing.usageCount = 0;
      }
    }
    package com.example;
    
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterMethod;
    
    class SomeClassDiffblueBase {
    
      @AfterClass
      public void resetTestEnvironment() {
        // clear test configuration
        Environment.state = null;
      }
    
      @AfterMethod
      public void resetLicenseUsageCount() {
        // reset license limits
        Licensing.usageCount = 0;
      }
    }
    package com.example;
    
    class SomeClass {
      void methodUnderTest(ComplexObject complex) {
        // ...
      }
    }
    package com.example;
    
    import org.junit.Before;
    
    class SomeClassDiffblueBase {
    
      static ComplexObject complex;
    
      @Before
      public void resetTestEnvironment() {
        complex = ComplexObject.builder()
          .withName("For Unit Tests")
          .withSquareNumber(64)
          .build();
      }
    }
    package com.example;
    
    import org.junit.jupiter.api.BeforeEach;
    
    class SomeClassDiffblueBase {
    
      static ComplexObject complex;
    
      @BeforeEach
      void resetTestEnvironment() {
        complex = ComplexObject.builder()
          .withName("For Unit Tests")
          .withSquareNumber(64)
          .build();
      }
    }
    package com.example;
    
    import org.testng.annotations.BeforeMethod;
    
    class SomeClassDiffblueBase {
    
      static ComplexObject complex;
    
      @BeforeMethod
      public void resetTestEnvironment() {
        complex = ComplexObject.builder()
          .withName("For Unit Tests")
          .withSquareNumber(64)
          .build();
      }
    }
    package com.example;
    
    import org.junit.Test;
    
    class SomeClassDiffblueTest extends SomeClassDiffblueBase {
    
      @Test
      public void testMethodUnderTest() {
        // Arrange
        SomeClass someClass = new SomeClass();
    
        // Act
        someClass.methodUnderTest(SomeClassDiffblueBase.complex);
    
        // Assert
        // ...
      }
    }
    package com.example;
    
    import org.junit.jupiter.api.Test;
    
    class SomeClassDiffblueTest extends SomeClassDiffblueBase {
    
      @Test
      void testMethodUnderTest() {
        // Arrange
        SomeClass someClass = new SomeClass();
    
        // Act
        someClass.methodUnderTest(SomeClassDiffblueBase.complex);
    
        // Assert
        // ...
      }
    }
    package com.example;
    
    import org.testng.annotations.Test;
    
    class SomeClassDiffblueTest extends SomeClassDiffblueBase {
    
      @Test
      public void testMethodUnderTest() {
        // Arrange
        SomeClass someClass = new SomeClass();
    
        // Act
        someClass.methodUnderTest(SomeClassDiffblueBase.complex);
    
        // Assert
        // ...
      }
    }

    Executed when passing the --coverage-reports option to the create command.

    Coverage reports can also be generated separately using the coverage-reports command.

    Upload to Cover Reports

    This phase uploads the coverage reports to Cover Reports.

    Executed when running the upload command.

    7. Upload the baseline coverage

    dcover upload http://localhost:8080

    8. Review results

    View Cover Reports

    View created tests in IntelliJ

    9. Push the changes

    We skip this step for the demo project.

    --maven
    --test-framework
    --active-profiles
    --ignore-stylechecks
    -D
    --environment
    partial test
    these prerequisites
    --preflight
    fix-build
    coverage-reports
    upload
    create
    --coverage-reports
    upload
    --preflight
    create
    create
    validate
    View Cover Reports

    Read all files, write all files.

    Unnecessary disk space is consumed, instability in unit tests.

    Allowed

    Unintended side effects across unit tests in a class, or test suite.

    Allowed

    Tests won't generate coverage for the native code.

    System.exit

    No

    No

    Causes the analysis service JVM to exit and would increase in the occurrence of R024/R025 output codes (from Diffblue Cover).

    Allowed

    Unintended side-effects with Kerberos systems.

    FAQ

    Unnecessary disk space is consumed, instability in unit tests.

    Unintended side effects across unit tests in a class, or test suite.

    regarding the use of these packages.
    by name. From one release to another, these classes may be removed, or they may be moved from one package to another, and it's fairly likely that their interface (method names and signatures) will change. (From Oracle's point of view, since we are committed to maintaining the Java platform, we need to be able to change
    sun.*
    to refine and enhance the platform.) In this case, even if you are willing to run only on Oracle's implementation, you run the risk of a new version of the implementation breaking your program.

    In general, writing java programs that rely on sun.* is risky: those classes are not portable, and are not supported.

    Tests won't generate coverage for the native code.

    System.exit

    No

    No

    Causes the analysis service JVM to exit and would increase in the occurrence of R024/R025 output codes (from Diffblue Cover).

    Unintended side-effects with Kerberos systems.

    Sandbox Policy Enabled (Default)

    Sandbox Policy Disabled (Changes Highlighted)

    Allow access to reflective Java operations (e.g. getting the list of methods of a class).

    Allow access to reflective Java operations (e.g. getting the list of methods of a class).

    Allow setting properties (JUnit needs this during test execution).

    Allow setting properties (JUnit needs this during test execution).

    Allow creating classloaders.

    Allow creating classloaders.

    Allow reads of all files.

    Allow reads of all files.

    Allow writes to files created in this session (including deletion).

    Allow writes of all files (including deletion).

    Allow writes of files in java.io.tmpdir (including deletion).

    Allow writes of all files (including deletion).

    Deny writes of files, not created in this session and outside of java.io.tmpdir (including deletion).

    Allow writes of all files (including deletion).

    Deny URL accesses (unless it's a file:// url with a GET request, in which case it's treated like a regular file operation).

    Allow URL accesses.

    Deny retrieving network information.

    Allow retrieving network information.

    Deny creating Sockets.

    Allow creating Sockets.

    Deny GUI access.

    Allow GUI access.

    Deny sun.misc.Unsafe/sun.misc.*

    Allow sun.misc.Unsafe/sun.misc.*

    Deny external process accesses.

    Allow external process accesses.

    Deny Java Management Extensions (JMX) access.

    Allow Java Management Extensions (JMX) access.

    Deny Java Native Interface (JNI) access.

    Allow Java Native Interface (JNI) access.

    Deny Smartcards (java.smartcardio.*).

    Allow Smartcards (java.smartcardio.*).

    Deny Printers (javax.print.*).

    Allow Printers (javax.print.*).

    Deny setting the security manager.

    Allow setting the security manager.

    Deny access control context.

    Allow access control context.

    Deny Kerberos Authentication access.

    Allow Kerberos Authentication access.

    Deny System.exit calls.

    Deny System.exit calls.

    Networking

    No

    Allowed

    Unexpected network traffic, data loss on remote machines, instability in unit tests.

    FileIO

    Read all files, write new files.

    Read all files, write all files.

    Data loss on the machine where Cover is running, instability in unit tests.

    TmpFileIO

    Read all files, write new files.

    GUI (Swing/AWT)

    No, java.awt.headless is set to true

    Allowed, java.awt.headless is set to false

    N/A

    sun.misc.*

    No

    Allowed

    Instability of tests across JVM vendors and operating systems.

    sun.misc.Unsafe

    No

    External Processes

    No

    Allowed

    Instability of unit tests, random behavior of other processes.

    JMX

    No

    Allowed

    Instability of unit tests, random behavior of JMX enabled beans/services/etc.

    JNI

    No, except JNI allow list - see below.

    Smartcards

    No

    Allowed

    Corruption of data on the smartcards.

    Printing

    No

    Allowed

    Print jobs are submitted to configured printers.

    Setting security manager

    No

    Allowed

    Unit tests won't be created or verified.

    Create access control context

    No

    Allowed

    Attempts to bypass sandbox will be allowed.

    Kerberos Authentication

    No

    R011
    allow-jni
    Working with code R012

    Read all files, write all files.

    Allowed

    Allowed

    Allowed

    FAQ
    public class Harmful {
        public void deleteRecursively(final Path root) {
            final File[] contents = directoryToBeDeleted.listFiles();
            if (contents != null) {
                for (final File file : contents) {
                    deleteRecursively(file);
                }
            }
            return directoryToBeDeleted.delete();
        }
    }

    Free trial

    Diffblue Cover free trial step by step demo - Cover Plugin and Cover CLI

    Trying out Diffblue Cover for the first time? Get up and running with the trial version of Cover Plugin for IntelliJ and Cover CLI – download, install, license, and play.

    eLearning

    Short on time? If you'd like a fast-track experience check out our free trial experience video. [7 min]

    A few points first...

    Cover components

    Cover is provided as an IDE plugin tool so you can write tests with one click in the IntelliJ IDE (Cover Plugin), a CLI application to write tests for your entire project (Cover CLI), and a CI integration to automatically write tests within your CI workflow (Cover Pipeline).

    Perfect partners

    Cover Plugin, Cover CLI, and Cover Pipeline are not mutually exclusive, in fact they make perfect partners. Use Cover Plugin within the IntelliJ IDE to write and check unit tests for your application during development, and also use Cover CLI directly from the IntelliJ Terminal/Console or your OS command line to access the wider and deeper functionality provided by Cover CLI - finally, use Cover Pipeline within your CI tool to automate the whole process and provide consistency across your organisation.

    The free trial

    This topic focuses on Cover Plugin and Cover CLI, and will take you through the key steps to download, install, and license both tools, as well as covering a few basics and getting some tests written using each tool. Cover Pipeline for GitLab is also available as a free trial version, see for details - for all other CI integrations please Diffblue.

    1. Sign up

    If you haven't already done so, sign up for the free trial - see .

    After successful sign-up, you'll receive a welcome email with general information and a license key for Cover Plugin and Cover CLI.

    2. Install Cover Plugin for IntelliJ

    You can install the Cover Plugin either from a downloaded ZIP archive or from the IntelliJ marketplace.

    1. Download the Diffblue Cover Plugin for IntelliJ as a .zip bundle from: &#xNAN;- The Diffblue website - or versions. &#xNAN;- The (IntelliJ Plugin Marketplace). &#xNAN;- The link sent to you via your Diffblue Cover welcome email. &#xNAN;- Your organization's internal file/app store.\

    2. In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).

    3. Install Cover CLI

    1. Download the Diffblue Cover CLI .exe installer or .zip file from: &#xNAN;- The Diffblue website - version. &#xNAN;- The link sent to you via your Diffblue Cover welcome email. &#xNAN;- Your organization's internal file/app store.\

    2. If you use the installer, run the .exe installer and follow the on-screen prompts - during installation you can select where to install Diffblue Cover.

    4. Apply licenses

    Once IntelliJ has restarted (after install), you'll be prompted for your license key (provided in your welcome email or by your organization) to activate the plugin. Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, see . Note that:

    • Applying a license provides access to the Teams and Enterprise Editions of Diffblue Cover.

    • Cover Plugin Community Edition is free to use but does require product verification to activate your perpetual license.

    • Offline license activation is available with the Diffblue Cover Enterprise Edition only. This can only be done through the CLI.

    5. Try it out

    Four steps to automatically write tests - clone an example project, compile the project and check your environment, learn a few basics, and then one click or one command to write tests.

    Step 1 - Clone the example project Spring PetClinic

    We're going to make use of an example project (Spring PetClinic) to show the Diffblue Cover Plugin for IntelliJ at work. First, we'll clone the project from the Git repo:

    1. Open a command line and navigate to where you want to clone this project.

    2. Run the following command:

    From IntelliJ select File > New... > Project from version control.

    • Ensure Git

    Step 2 - Compile the project and check your environment

    Before we write any tests, we need to compile the PetClinic project. Diffblue Cover works by analyzing the bytecode of any project used with Cover. You can do this from the Maven plugin in IntelliJ (click the Maven tab, open petclinic > Lifecycle, and double-click package) or open a command line, navigate to the directory containing the PetClinic project, and run the Maven package command:

    Basic prerequisites:

    • Java 8, 11, 17, or 21 compatible source code, or Kotlin source code.

    • Maven 3.2.5+ or Gradle 4.9+ build tools.

    • Any project (for use with Diffblue Cover) must compile and run with no failing unit tests. JUnit and TestNG testing frameworks are supported.

    More details:

    Diffblue Cover requires that the system environment (hardware, operating system, network connectivity, Java installation) as well as the project environment (build tooling, dependencies, presence of artifacts, existing unit tests) meet the minimum requirements as detailed in . Cover will perform an environment check before analysis begins to ensure that the requirements are met - if there are any issues, these will be reported via the Diffblue Cover panel in IntelliJ using E(Environment) .

    Check your environment:

    Cover CLI also provides a command line option to run these checks, without writing any tests, useful when you just want to check-out your environment without doing anything else. To run a preflight environment check, open a command line, navigate to the directory containing the PetClinic project, and run the preflight checks:

    Step 3 - A few basics

    Before we start using Diffblue Cover to write tests, it's worth covering a few basics first.

    We won't cover the whole UI here, but here are a few useful gutter icons to get you started:

    Icon
    Description

    Step 4 - Automatically write tests for the example project

    In this step we're going to use Diffblue Cover to automatically write tests for two classes and then for the entire PetClinic project. We'll make use of Cover Plugin for IntelliJ and run Cover CLI commands from a command line. You can also use Cover CLI straight from the IntelliJ terminal - handy when you’re using both tools in partnership

    Note that the examples here use DiffblueTest as the default class name suffix and diffbluetest as the default method name prefix, just to highlight the tests created by Diffblue Cover.

    • To change your suffix and prefix in IntelliJ, go to Diffblue > Change Settings > Test Naming > Class Template/Method Template.

    • To change your suffix and prefix in Cover CLI, use the --class-name-template and --method-name-template command arguments - see Cover CLI for details.


    First we'll use Cover Plugin for IntelliJ:

    1. In IntelliJ, open the PetClinic project and navigate to a class - for example, OwnerController.

    2. To create tests for this class, click on the Write Tests gutter icon next to the line class OwnerController.

    3. Click the links in the Diffblue Cover panel to see the tests produced. And that's it, simple - 1 click, 9 methods analyzed, 7 tests written, around 340 lines of code, and all in around 65 seconds - computationally perfect, human readable. You'll find these tests in the test


    Now we'll move on to using Cover CLI.

    1. Open a command line or open the IntelliJ terminal, and navigate to the demo-spring-petclinic folder.

    2. Enter the following command to write tests for the PetController class:

    1. Cover CLI will now write the tests for the class - 1 command line, 10 methods analyzed, 9 tests written, around 214 lines of code created, and again, all in around 65 seconds - computationally perfect, human readable. You'll find these tests in the test folder for the project.

    1. Once you're happy with this first set of tests, create the full test suite for the entire PetClinic project - enter dcover create. That's it, two "words" and you're done. Of course this one takes a little longer to complete (around five minutes) as it creates tests across the entire PetClinic project, analyzing 97 methods and creating 77 tests (exact count may vary slightly).

    More...

    What does Diffblue Cover do?

    • Diffblue Cover first ensures that your code is compiled and examines each method that Cover will create tests for, including any dependent methods.

    • Cover then creates initial test candidates and uses reinforcement learning to evaluate and adjust the test candidate for each method. This process is repeated until the set of tests that optimize coverage are selected and committed to your code base.

    Next steps

    Now you're up and running with Diffblue Cover:

    • Have a scan through the topic which provides some additional source code examples along with an explanation of the tests created by Diffblue Cover.

    • Create some tests for your own project - as long as you have a project that compiles and your environment meets the Cover , you're literally a click away from AI written tests, created in seconds instead of hours.

    • See and to familiarize yourself with the full set of features and functions.

    If you're only planning to use Cover Plugin Community Edition (free), you may just want to jump straight to the topic.

    Notes

    Demo code, statistics, and timings used throughout Diffblue docs and eLearning videos are based on in-house demonstrations. These may differ slightly from those experienced within a live production environment.

    Customizing test inputs

    How to customize test inputs

    By default, Diffblue Cover will automatically choose input values to use when writing tests, but it's possible to provide custom inputs that may unlock additional coverage.

    Background

    A key feature of Diffblue Cover is automatically identifying appropriate inputs necessary to write tests for a given method under test.

    However, sometimes Diffblue Cover is unable to find appropriate inputs and thus does not produce useful tests. One such example is with the open source XXL-JOB project where Cover fails to produce tests for the CronExpression class, resulting in an output code:

    Also, because the

    Click on the cog icon next to the Installed tab and select Install Plugin from Disk.... Navigate to the location of the plugin, select the zip file, and click OK.

  • When prompted, click Restart IDE to complete the install.

    1. In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).

    2. Select the Marketplace tab, search for Diffblue, and click Install. Your plugin will now be downloaded and installed.

    3. When prompted, click Restart IDE to complete the install.

    If you use the archive file, extract the .zip file to an appropriate installation folder. Add the install folder path to your the PATH environment variable or create a new %DCOVER% environment variable and add that to PATH.
  • When your done, restart your PC. Once complete, open Windows PowerShell and enter dcover version to check the install and PATH configuration - if all is OK, Cover will display the current version.

    1. Download the Diffblue Cover CLI .zip file from: &#xNAN;- The Diffblue website - Free Trial version. &#xNAN;- The link sent to you via your Diffblue Cover welcome email. &#xNAN;- Your organization's internal file/app store.\

    2. Unzip the Cover CLI zip file to an appropriate installation location (for example, ~/bin) and add this location in the PATH environment variable using the following example commands:\

      Reminder: Make sure that the PATH environment variable is set permanently according to your operating system instructions.

    3. Once complete, run dcover version to check the install and PATH configuration - if all is OK, Cover will display the current version.

    See Cover Editions and Licensing for more details.

    Diffblue Cover requires a remote license check with the Diffblue licensing server each time it's used. For help troubleshooting license keys, network connections, and proxy server settings, as well as details of offline licensing (Enterprise Edition only), see Licensing.

    • To activate your license, open Windows PowerShell (Windows) or Terminal (macOS/Linux) and enter the command dcover activate <license-key> - replace <license-key> with the license key provided in your welcome email or provided by your organization.

    • Entering multiple different license keys will overwrite the existing key.

    • You can check your license status by running the command dcover license

    is selected in
    Version control
    .
  • Enter https://github.com/diffblue/demo-spring-petclinic as the URL.

  • Select the directory/folder to clone the project to.

  • When you're ready, click Clone.

  • We won't cover every CLI command option, but here are a few details to get you started:

    Command
    Description

    dcover help

    Help - get, err, help. Use this with the other commands as well to get some details of what options are available (like dcover create help to get details of the available optional arguments).

    dcover activate

    <license-key>

    Activate License - apply/activate a license. Replace <license-key> with the license key provided in your welcome email or provided by your organization.

    dcover license

    Check License - display your current license status.

    dcover version

    Check Version - display the version of Diffblue Cover CLI.

    dcover create

    Create Tests - write tests for the project (run from the root directory of the project). You can restrict this further by simply specifying the method or class path - this is detailed a little further in the example in Step 4 below.

    folder for the project.
    Cover Pipeline for GitLab is also available as a free trial version, see
    for details - for all other CI integrations please
    Diffblue.

    Write tests - click this icon to write tests for this method or class.

    Not testable - this method or class can't be tested. Click the icon to find out why.

    Private method - this method can't be tested as it's private, although it may be tested indirectly via a public method. If you'd like Cover to write unit tests for this method, you can either make the method public or package protected.

    Test maintenance - displayed next to test classes and methods in project test files. Click the icon to update or delete tests for the method or class.

    Cover Pipeline for GitLab
    contact
    https://www.diffblue.com/try-cover
    Free Community Edition
    Free Trial
    JetBrains Marketplace
    Free Trial
    Licensing
    Specs & Reqs
    Output Codes
    Commands & Arguments
    Test examples
    prerequisites
    Cover Plugin
    Cover CLI

    Delete test - displayed next to your test methods in project test files. Click the icon to delete a test method.

    Cover Pipeline for GitLab
    contact
    R013
    occurs in the primary constructor for the class under test, Diffblue Cover is then unable to produce
    CronExpression
    instances for a further 28 methods and
    output codes:

    These tests need input strings of a very specific format in order to successfully construct a CronExpression instance. In fact the javadoc in CronExpression.java devotes over 100 lines of comments to explaining the requirements for this format - helpfully providing an example of a valid cron expression string: "0 0 14-6 ? * FRI-MON".

    With this configuration file in place, when java.lang.String values are required, Diffblue Cover will try to use the constant cron expression value (immediate: "0 0 14-6 ? * FRI-MON") if the parameter begins with cronExpr (parameter: cronExpr). Using just this one custom input allows this class to go from 54 tests with 21% line coverage to 194 tests with 59% line coverage.

    eLearning

    Custom Inputs

    You can specify custom inputs in a DiffblueRules.yaml or DiffblueRules.yml file. If both files exist in the same directory then both are read, with the .yaml variant taking precedence.

    Diffblue Cover will stop with an E068 error if the file is malformed due to wrong indentation or invalid rule syntax. This behavior is intended to give quick feedback so that the identified problem can be addressed, rather than waste time and resources attempting to create tests without all the custom rules.

    If a rule is read successfully but the class can't be found, an E143 warning will be given. This may be due to the class not being available (e.g. in a different module) or due to an incorrect class name. Test generation will not be stopped in this case.

    Custom Inputs for Strings

    When writing unit tests, by default Diffblue uses predefined / context-based values for String objects. However, the user can come up with a specific String such as a name or a password. For example if the user needs to use “Peter” wherever in the codebase an argument called clientName appears and “rabbit” for an argument called password, the syntax will be:

    This is shown in the image below:

    Custom Inputs for Primitives

    When writing unit tests, by default Diffblue uses predefined / context-based values for primitives such as int, long, etc. However, the user might want to push a certain value when tests are being written. For example, if the user wants a value of 11 for all primitives of type long to be used in the whole codebase, the following lines should be added in the DiffblueRules.yaml:

    If a particular primitive of long type such as 0987654321 is needed to match a certain method argument such as accountNumber in the whole codebase, the syntax should be:

    Finally, the user might decide to target a given method and one of its arguments. For example if the user wants the argument called amount in the method addBalance() to take the value 16, a syntax like this should be used:

    This is shown in the image below:

    Custom Inputs for .properties files

    Sometimes the user wants to use specific arguments such as URIs from a given file such as a .properties file.

    For example:

    production-env.properties contains baseUri=https://app.example.com/

    and

    staging-env.properties contains baseUri=http://app.staging.example.com:8080/

    To have these URIs used in unit tests, there two options depending on the accessibility of the .properties files:

    1. Using files from the resources directory

    In order to use http://app.staging.example.com:8080/ from the staging-env.properties file in your unit tests, add the below lines to the DiffblueRules.yaml file. Note that for resource property files the path is taken from the module's test classpath location.

    2. Using files at the root of the project

    In order to use http://app.staging.example.com:8080/ from the staging-env.properties file in your unit tests, add the below lines to the DiffblueRules.yaml file. Note that for file property files the path is taken from the root of the project.

    Rules Location

    Custom rules are loaded from the project working directory and any of its ancestor directories. Assuming you have your project checked out into ~/Projects/MyProject and are working with a module SomeModule within that, then rules will be read from each of the following locations in order, if they exist:

    • ~/Projects/MyProject/SomeModule/DiffblueRules.yaml

    • ~/Projects/MyProject/SomeModule/DiffblueRules.yml

    • ~/Projects/MyProject/DiffblueRules.yaml

    • ~/Projects/DiffblueRules.yaml

    • ~/DiffblueRules.yaml

    • …

    • /DiffblueRules.yaml

    The intention here is that module and project level rules can be checked into the project source control system, but additional fallbacks into the user home directory are also possible. Rules are loaded from each discovered file in order, and so applicable rules local to the module will take precedence over rules defined at a wider scope.

    Rules Format

    Custom rules are defined in a YAML format with the structure shown here. Rules are grouped by the type of input produced, and so the top level keys are the type being produced, each with a list of rules at the next level down. For example the following would mean that the constant values "Diffblue", "Cover", "Custom", "Inputs" are all considered as candidate values to use whenever a String is required. Note that this does not guarantee that all of these constant values will be used, in practice the first candidate constant value may produce full coverage and so further candidate values are not needed.

    immediate: Rule

    The first supported mechanism for producing values is via immediate constant values. This mechanism supports primitives, java.lang.String, and single- or multi-dimensional arrays of those types. Rules using this mechanism will have an immediate: <constant> component. Arrays of immediate values can be specified by adding one or more [] at the end of the normal type declaration, then using one of the YAML syntaxes for a list of values. For example, the following configuration specifies a single unconditional default rule for each supported type:

    factory: Rule

    The second supported mechanism for producing values is via factory methods. This mechanism supports producing class and interface instances and their single- or multi-dimensional arrays, but not enumerations, java.lang.String or primitives.

    Factory methods must meet the following criteria in order to be used:

    • Must be static methods or constructors.

    • Must have public visibility.

    • Any parameters must be able to take primitives, java.lang.String, java.lang.Class, or single- or multi-dimensional arrays of those types.

    • Must have a return type assignable to the requested type.

    Any factory methods that don't fit these criteria, or cannot be loaded with the user's classpath, will be silently ignored.

    The factory rule syntax uses the factory: key with the following sub-keys:

    • method: – Specifies the class and method name (e.g. com.example.Foo.create). For constructors, use <init> (e.g. com.example.Book.<init>).

    • (optional) params: – Lists the arguments passed to the method or constructor. If the method or constructor has parameters, they must be provided. If there are no parameters, this can be omitted.

    Cover will automatically determine the correct method or constructor based on the method name provided in the method: sub-key and values provided in the params:sub-key, selecting the most appropriate match. See Handling Ambiguous Matches if more specificity is needed.

    For example, if you are working with a library then you might need to deal with International Standard Book Numbers in the form of an ISBN class, created by parsing ISBN formatted strings. Custom rules could be used to specify some valid ISBN values that can be used to test methods that require an ISBN instance:

    Handling Ambiguous Matches

    Sometimes there are several constructors or factory methods for an object that accept the same number of parameters and compatible types. To specify exactly which method to use, you can provide a full method descriptor.

    For example, a class may have multiple constructors:

    In this case, Cover cannot know whether you intended to use the no-argument constructor or the one with a single String parameter. It will proceed with one of the matches (typically the first match it finds with the fewest parameters).

    To explicitly specify which constructor or method to use, you can provide a full javap-style descriptor, for example:

    or

    The identifier must include a colon followed by a full javap-style method descriptor.

    field: Rule

    The field rule can be used to produce values using constant fields. This mechanism supports object instances, java.lang.String, primitives and enumeration constants.

    Fields must meet the following criteria in order to be used:

    • Must have public visibility.

    • Must be static .

    • Must be final .

    • Must have a type assignable to the requested type.

    The field can be identified in the rule by using the fully qualified class name, followed by a dot, followed by the field name. For example, if you are working double values you could use the java.lang.Math.PI field as an input:

    You can also load enumeration constants. For example, given the following example:

    You can specify specific enumeration constants to use as inputs using field rules:

    properties: Rule

    The properties rule is a special case rule specifically for creating and populating a java.util.Properties instance.

    The properties rule can specify a file using an absolute or relative path to a .properties file. When an absolute path is provided then that absolute path will be used directly from the test. When a relative path is provided then the properties file will be located relative to the DiffblueRules.yaml, and will be re-resolved against the project's working directory.

    For example, given the following rule supplied in the project root:

    Then tests will attempt to populate a java.util.Properties instance as follows:

    Alternatively the properties rule can specify a classpath resource to load. Resources are loaded relative to the class under test, so typically an absolute resource path should be used.

    For example, given the following rule:

    Then tests of ExampleApp will attempt to populate a java.util.Properties instance as follows:

    Conditions

    Typically a custom constant value is associated with one or more conditions for when this custom value should be used. When producing inputs for a particular method, supported conditions allow matching against the fully qualified class name, method name, or parameter name. For ease of use, matching is typically performed using case-insensitive substrings, but if finer control is required then the pattern can be wrapped in a ^ and $ and the pattern will be treated as a regular expression instead.

    Consider the following example code under test and the numbered contexts where string inputs need to be produced:

    class: Condition

    Class name conditions match against the fully qualified class name, com.example.myapp.StringProcessor in context #1-4 above, or com.example.myapp.NumberProcessor in context #5. For example class: "example.myapp" and class: "^.*Processor$" could both be used to match all contexts above.

    method: Condition

    Method name conditions match against the name of the method, parse in context #1 above, concatenateStrings in #2-3. For example method: "parse" would match context #1, whereas method: "^.*String.*$" would match contexts #2-4.

    parameter: Condition

    Parameter name conditions match against the name of the parameter, text in context #1 above, str1 in contexts #2,4,5. For example parameter: "text" would match context #1 above, parameter: "^str.*$" would match contexts #2-5.

    Condition Combination

    Up to one of each condition can be combined in a single rule, so for example the following rule can be used to offer the input "Hello World!" only in context #4 above:

    When combining conditions with rules be careful about using the correct indentation, i.e., the condition should be indented to the same level as the rule itself. For example, when using a factory: rule with a class: condition the correct indentation is:

    Note that the class: key is aligned with the factory: key, while method: and params: sub-keys of factory: are indented by 2 extra spaces.

    Full example

    R013
    R008
    mkdir ~/bin
    cd ~/bin
    unzip ~/diffblue-cover*.zip
    export PATH=$PATH:~/bin
    git clone https://github.com/diffblue/demo-spring-petclinic
    cd demo-spring-petclinic
    ./mvnw package
    cd demo-spring-petclinic
    dcover create --preflight
    package org.springframework.samples.petclinic.owner;
    
    import ...
    
    @ContextConfiguration(classes = {OwnerController.class})
    @ExtendWith(SpringExtension.class)
    class OwnerControllerDiffblueTest {
    	@Autowired
    	private OwnerController ownerController;
    
    	@MockBean
    	private OwnerRepository ownerRepository;
    
    	/**
    	 * Method under test: {@link OwnerController#initCreationForm(Map)}
    	 */
    	@Test
    	void diffbluetestInitCreationForm() throws Exception {
    		MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/owners/new");
    		MockMvcBuilders.standaloneSetup(ownerController)
    			.build()
    			.perform(requestBuilder)
    			.andExpect(MockMvcResultMatchers.status().isOk())
    			.andExpect(MockMvcResultMatchers.model().size(1))
    			.andExpect(MockMvcResultMatchers.model().attributeExists("owner"))
    			.andExpect(MockMvcResultMatchers.view().name("owners/createOrUpdateOwnerForm"))
    			.andExpect(MockMvcResultMatchers.forwardedUrl("owners/createOrUpdateOwnerForm"));
    	}
    
    ....
    dcover create org.springframework.samples.petclinic.owner.PetController
    package org.springframework.samples.petclinic.owner;
    
    import ...
    
    @ContextConfiguration(classes = {PetController.class})
    @ExtendWith(SpringExtension.class)
    class PetControllerDiffblueTest {
    	@MockBean
    	private OwnerRepository ownerRepository;
    
    	@Autowired
    	private PetController petController;
    
    	/**
    	 * Method under test: {@link PetController#populatePetTypes()}
    	 */
    	@Test
    	void diffbluetestPopulatePetTypes() {
    		ArrayList<PetType> petTypeList = new ArrayList<>();
    		when(ownerRepository.findPetTypes()).thenReturn(petTypeList);
    		Collection<PetType> actualPopulatePetTypesResult = petController.populatePetTypes();
    		assertSame(petTypeList, actualPopulatePetTypesResult);
    		assertTrue(actualPopulatePetTypesResult.isEmpty());
    		verify(ownerRepository).findPetTypes();
    	}
    ....
    com.xxl.job.admin.core.cron.CronExpression.<init>
      R013: No inputs found that don't throw a trivial exception
        Diffblue Cover tried to run the arrange/act section, but the method under
        test threw
        java.lang.NullPointerException
            at com.xxl.job.admin.core.cron.CronExpression.<init>(CronExpression.java:295)
        In order to prevent <init>(CronExpression)
        from throwing NullPointerException, add constructors or factory
        methods that make it easier to construct fully initialized objects used in
        <init>(CronExpression).
        See https://diff.blue/R013 to resolve this issue.
    com.xxl.job.admin.core.cron.CronExpression.addToSet
      R008: Failed to instantiate class under test
        Diffblue Cover was unable to construct an instance of CronExpression.
        Add a package-visible constructor or a factory method for testing which
        (ideally) takes no arguments, and does not throw, return null or return
        a subtype.
        See https://diff.blue/R008
    java.lang.String:
      - immediate: "0 0 14-6 ? * FRI-MON"
        parameter: cronExpr
    java.lang.String:
      - immediate: "Peter"
        parameter: clientName
      - immediate: "rabbit"
        parameter: password
    long:
       - immediate: 11
    long:
     -  immediate : 987654321
        parameter: accountNumber
    long:
      - immediate: 16
        parameter: amount
        method: addBalance
    java.util.Properties:
      - properties:
          resource: /staging-env.properties
    java.util.Properties:
      - properties:
          file: /staging-env.properties
    java.lang.String:
      - immediate: "Diffblue"
      - immediate: "Cover"
      - immediate: "Custom"
      - immediate: "Inputs"
    boolean:
      - immediate: true
    
    byte:
      - immediate: 65 # 0x41
    
    char:
      - immediate: '*'
    
    float:
      - immediate: 888.888f
    
    double:
      - immediate: 12345.6789
    
    int:
      - immediate: 7 # low values are recommended in case used for resource allocation
    
    long:
      - immediate: -23
    
    short:
      - immediate: 291 # 0x0123
    
    java.lang.String:
      - immediate: "Lorem ipsum dolor sit amet"
    
    java.lang.String[]:
      - immediate: [ "Hello", "World!" ]
      - immediate: # this rule uses different syntax for the same rule as above
        - "Hello"
        - "World!"
    
    java.lang.String[][]:
      - immediate: [ [ "Multidimension", "arrays" ], [ "are", "also", "supported" ] ]
      - immediate: # this rule uses different syntax for the same rule as above
        - [ "Multidimension", "arrays" ]
        - [ "are", "also", "supported" ]
      - immediate: # this rule uses another syntax variation for the same rule
        - - "Multidimension"
          - "arrays"
        - - "are"
          - "also"
          - "supported"
    com.example.Book:
      - factory:
          method: com.example.Book.<init>
          params: [ "Title" ]
    com.example.ISBN:
      - factory:
          method: com.example.ISBN.parse
          params: [ "1-56619-909-3" ] # An 'old' style ISBN-10 formatted identifier
      - factory:
          method: com.example.ISBN.parse
          params:
            - "978-1-56619-909-4" # A 'new' style ISBN-13 formatted identifier
      - factory:
          method: com.example.Platform.getBean
          params: [ com.example.ISBN ]
    # For arrays 
    com.example.ISBN[]:
      - factory:
          method: com.example.ISBNTestSupport.getIsbnArray
    public Book() {}
    public Book(String title) {}
    com.example.Book:
      - factory:
          method: com.example.Book.<init>
    com.example.Book:
      - factory:
          method: com.example.Book.<init>:()
    com.example.Book:
      - factory:
          method: com.example.Book.<init>:(Ljava/lang/String;)
    double:
      - field: java.lang.Math.PI
    package com.example.myapp;
    
    public enum MyEnum {
       ONE,
       TWO,
       THREE
    }
    com.example.myapp.MyEnum:
      - field: com.example.myapp.MyEnum.ONE
      - field: com.example.myapp.MyEnum.TWO
    java.util.Properties:
      - properties:
          file: relative-file.properties
    BufferedReader newBufferedReaderResult =
      Files.newBufferedReader(Paths.get("relative-file.properties"));
    
    Properties properties = new Properties();
    properties.load(newBufferedReaderResult);
    newBufferedReaderResult.close();
    java.util.Properties:
      - properties:
          resource: /resource.properties
    InputStream resourceAsStream =
      ExampleApp.class.getResourceAsStream("/resource.properties");
    
    Properties properties = new Properties();
    properties.load(resourceAsStream);
    resourceAsStream.close();
    package com.example.myapp;
    
    public class StringProcessor {
    
      public static int parse(String text /* Context #1 */) {
        try {
          return Integer.parseInt(text);
        } catch (NumberFormatException e) {
          throw new IllegalArgumentException("Invalid input: " + text);
        }
      }
    
      public static String concatenateStrings(String str1 /* Context #2 */, String str2 /* Context #3 */) {
        return str1 + str2;
      }
    
      public static int getStringLength(String str1 /* Context #4 */) {
        return str1.length();
      }
    }
    package com.example.myapp;
    
    public class NumberProcessor {
    
        public static int processNumber(String str1 /* Context #5 */) {
            try {
                return Integer.parseInt(str1);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Invalid input: " + str1);
            }
        } 
    }
    
    java.lang.String:
      - immediate: "Hello World!"
        method: "concatenateStrings"
        parameter: "str1"
    java.io.File:
      - factory:
          method: java.io.File.<init>:(Ljava/lang/String;)V
          params: [ src/test/resources/testJPEG.jpg ]
        class: "com.example.SomeClass"
    java.lang.String:
      # Matches the first argument of the `concatenateStrings` method
      - immediate: "Hello "
        method: "concatenateStrings"
        parameter: "str1"
      # Matches the second argument of the `concatenateStrings` method
      - immediate: "World!"
        method: "concatenateStrings"
        parameter: "str2"
      # Matches arguments of methods whose name contains `String`
      - immediate: "Hello"
        method: "^.*String.*$"
      # Matches all arguments of methods in the `NumberProcessor` class
      - immediate: "800"
        class: com.example.myapp.NumberProcessor
      # Matches all arguments whose name starts with `str`
      - immediate: "Hello World!"
        parameter: "^str.*$"

    dcover create --<arguments>

    Optional Arguments - there's a few, OK quite a lot. The optional arguments provide access to deeper functionality within Cover CLI such as creating coverage reports, specifying a build configuration file, and running preflight checks (this one is used in Step 3 below).

    Specs & Reqs

    Environment prerequisites, plus system specifications and requirements

    Prerequisites

    Diffblue Cover requires that the system environment (hardware, operating system, network connectivity, Java installation) as well as the project environment (build tooling, dependencies, presence of artifacts, existing unit tests) meet the minimum requirements as outlined below. Diffblue Cover will perform an environment check before analysis begins to ensure that the requirements are met.

    Cover CLI provides a --preflight option (see ) which can be used to check the status of the prerequisites without performing the project analysis. This option can also be run without a license key.

    Cover Plugin & Cover CLI

    • 32 GB RAM, 5 GB minimum available disk space, 4 CPU cores

    • 8GB Java heap allocated

    • TCP connection *

    • Windows 11 Pro, Windows 10 Enterprise, Ubuntu 18.04, RHEL 7.7, macOS 10.15

    * Cover requires the use of an analysis service that communicates with Cover Plugin and Cover CLI via TCP connections on localhost. In particular, Cover must be able to start up the analysis service and open a bi-directional TCP connection between the frontend and the service.

    Cover Plugin

    • IntelliJ Community or Ultimate version 2025.2 or 2025.1

    • A minimum of 4GB memory allocated to IntelliJ

    Cover Pipeline for GitLab

    • GitLab subscription - Free, Premium, or Ultimate Edition.

    Cover Reports

    Server hosting Cover Reports - Cover Reports Administrator:

    • 4GB RAM (8GB recommended), 2GB* minimum available disk space, 4 CPU cores.

    • 2GB Java heap allocation, 4GB recommended.

    • Docker Install - Docker Engine 20.10.17, Docker Compose v2.10.2, and if you're using Docker Hub you'll also need an internet connection.

    • Zip Install & Windows Installer - Java JDK 17+ (and available in your PATH system environment variable). For production use, you'll also need to provide a vanilla PostgreSQL 14 database (see Cover Reports >

    * Note that the database server will store the data uploaded to Cover Reports. Sufficient storage should be ensured for projected usage.

    Client workstation - Cover Reports Contributor:

    • Diffblue Cover CLI

    • Java 8 and 11 Projects: JaCoCo 0.8.3+

    • Java 17 Projects: JaCoCo 0.8.7+

    • Java 21 Projects: JaCoCo 0.8.11+

    Client workstation - Cover Reports User:

    • The latest version of Chrome, Edge, Safari, or Firefox with a screen resolution of 1920 x 1080 or higher.

    • Network connectivity between the user's workstation and the Cover Reports server.

    Cover Refactor

    OpenRewrite Maven or Gradle plugin (and its transitive dependencies) must be available in your local Maven or Gradle mirror.

    • OpenRewrite Gradle plugin: 6.12.0

    • OpenRewrite Maven plugin: 5.28.0

    Spring

    Spring and Spring Boot versions are required to be compatible with your version of Java, as well as each other. Diffblue Cover supports the following:

    • Java 8 Projects: Spring Boot 1.3.3 to 2.7.x, Spring Core 4.1.1 to 5.3.x

    • Java 11 Projects: Spring Boot 2.1.0 to 2.7.x, Spring Core 5.1.0 to 5.3.x

    • Java 17 Projects: Spring Boot 2.4.0 to 3.1.x, Spring Core 5.3.1 to 6.0.x

    • Java 21 Projects: Spring Boot 2.4.0 to 3.1.x, Spring Core 5.3.1 to 6.0.x

    Dependencies

    Dependencies required for running tests should be in the project configuration. Additional libraries may also be necessary depending on the project under test.

    Dependency
    When
    Version

    Other dependencies listed below may be needed, if they are transitive dependencies of your project. If one of these dependencies is required but missing, tests will be generated for some classes but not others. A message will appear in the console output indicating a missing dependency.

    Dependency
    Version

    Spring projects and Hamcrest

    Either:

    • Use the spring-boot-starter-test dependency to add Hamcrest.

    • Add org.hamcrest:hamcrest. The version of Hamcrest needs to match the relevant version of spring-boot-test. For example, if the user has spring-boot-test:2.4.6, they should look at the dependency list: . This shows that the matching version is Hamcrest 2.2 (you may have to scroll).

    Spring WebFlux projects and Spring Security

    When Spring Security is configured for a project in order to unlock full test generation capabilities for Spring WebFlux controllers write a custom configuration to deactivate CSRF(Cross-Site Request Forgery) security for unit tests, which can later be imported in the base class for your test:


    System Specifications & Requirements

    Supported Operating Systems

    OS
    Cover CLI
    Cover Plugin

    Supported IntelliJ Versions

    Cover Plugin for IntelliJ supports the latest and the previous versions of IntelliJ.

    IntelliJ
    Cover Plugin
    Last Supported Cover Version

    Supported Java Versions

    Java Version
    Cover CLI
    Cover Plugin

    Note that only 64 bit versions of Java are supported.

    Supported Jakarta EE Versions

    Jakarta
    Cover CLI
    Cover Plugin

    * Note that Diffblue Cover does not use Jakarta EE application context for tests, all injected dependencies will be mocked.

    Supported Spring Versions

    Spring *
    Cover CLI
    Cover Plugin

    Spring, Spring Boot and Spring WebFlux versions are required to be compatible with your version of Java, as well as each other.

    Supported Kotlin Versions

    Currently all 64 bit versions of Kotlin are supported.

    Kotlin
    Cover CLI
    Cover Plugin

    Note that Cover writes Java tests for Kotlin code, so you will also need a suitable Java installation with appropriate Java dependencies.

    Supported Build Tools

    Tool
    Cover CLI
    Cover Plugin

    Supported Test Frameworks

    Framework
    Cover CLI
    Cover Plugin

    JUnit 4

    Diffblue Cover supports JUnit 4, from JUnit 4.11 to JUnit 4.13. In the CLI, you can force the usage of JUnit 4 by passing the --testing-framework=junit-4 option. In the plugin, you can select JUnit 4 as a testing framework in the settings dialog.

    JUnit Jupiter 5

    Diffblue Cover supports JUnit Jupiter, from JUnit Jupiter 5.0 to JUnit Jupiter 5.12.2 In the CLI, you can force the usage of JUnit 5 by passing the --testing-framework=junit-5 option. In the plugin, you can select JUnit 5 as a testing framework in the settings dialog.

    You may need some specific set-up for your build system to work properly with JUnit 5, in particular if you wish to use Diffblue Cover's built-in test validation. See Building a Gradle project or Building a Maven project for details.

    TestNG 6 and 7

    Diffblue Cover supports TestNG versions 6 and 7. In the CLI, you can force the usage of TestNG by passing the --testing-framework=testng option. In the plugin, you can select TestNG as a testing framework in the settings dialog.

    Supported Mock Frameworks

    Framework
    Cover CLI
    Cover Plugin

    Supported JaCoCo Versions

    JaCoCo
    Cover CLI
    Cover Plugin

    Supported Jersey Versions

    Jersey
    Cover CLI
    Cover Plugin

    For Jersey 2 and 3 support, the following dependencies are required for test generation:

    • org.glassfish.jersey.test-framework:jersey-test-framework-core

    • org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-inmemory

    Coverage Measurement

    Tool
    Cover CLI
    Cover Plugin

    Creating Tests - Scope

    Level
    Cover CLI
    Cover Plugin

    * For Cover Plugin, this feature is not available in the Community Edition.

    ** For Cover Plugin, this feature is only available in the Enterprise Edition.

    Cover Reports

    Database
    Docker
    Zip

    * For Cover Reports, when using our Docker distribution Postgres 14 is included. When using Zip distribution, H2 is included. However you can provide a self hosted Postgres 14 database for production purposes. We support vanilla Postgres 14. Postgres 15+ versions and alternative distributions can be used at your own risk.

    Java 8 (8u351+), Java 11 (11.0.17+), Java 17 (17.0.5+) or Java 21 (21.0.1+). Note only 64-bit versions of Java are supported.

  • For Maven projects: Maven version 3.2.5+

  • For Gradle projects: Gradle version 4.9+ (must be compatible with your version of Java).

  • For Ant projects: Ant version 1.10.4+

  • JUnit 4.11 - 4.13, JUnit 5.0 - 5.12.2, or TestNG 6.0.1 - 7.10.2.

  • For Java 8 projects: Mockito 1.9.5 - 4.11.0

  • For Java 11 projects: Mockito 2.22.0 - 5.20.0

  • For Java 17 projects: Mockito 4.1.0 - 5.20.0

  • For Java 21 projects: Mockito 4.1.0 - 5.20.0

  • For Kotlin projects: one of the above versions of Java and associated Mockito

  • All necessary tooling to build the project

  • The project must compile and run with no failing unit tests

  • Access to a dependency repository to download transient dependencies

  • Access to the Diffblue licensing server for remote license check

  • ).
  • Windows Install - Windows Server 2019 and above, Windows 10 and above.

  • All - Network connectivity between the server(s) and client workstations. Note that if the Cover Reports server and database server are on different hosts, good network connectivity between them will ensure good performance.

  • Network connectivity between the user's workstation and the Cover Reports server.

    Kotlin Projects: any of the above combinations to support the Java tests

    Spring Boot Test ( org.springframework:spring-boot-test)

    When using Spring Boot ( org.springframework:spring-boot)

    2+, matching version

    Spring Boot Starter Test ( org.springframework.boot:spring-boot-starter-test)

    When using Spring Boot ( org.springframework:spring-boot) for Spring WebFlux projects

    2+, matching version

    Spring Test (org.springframework:spring-test)

    When using Spring ( org.springframework:spring-core) unless using Spring Boot

    4.1.1+, matching version

    Spring Boot Test Autoconfigure ( org.springframework.boot:spring-boot-test-autoconfigure)

    When using Spring ( org.springframework:spring-core) for Spring WebFlux projects unless using Spring Boot

    2+, matching version

    Mockito (org.mockito:mockito-core)

    4.1.0+ for Java 21

    4.1.0+ for Java 17

    2.22.0+ for Java 11

    1.9.5+ for Java 8

    macOS 10.15

    ✅

    ✅

    IntelliJ 2024.1 (Community + Ultimate)

    ✅

    2024.11.02

    IntelliJ 2023.3 (Community + Ultimate)

    ✅

    2024.08.01

    IntelliJ 2023.2 (Community + Ultimate)

    ✅

    2024.04.02

    IntelliJ 2023.1 (Community + Ultimate)

    ✅

    2023.12.02

    IntelliJ 2022.3 (Community + Ultimate)

    ✅

    2023.07.03

    IntelliJ 2022.2 (Community + Ultimate)

    ✅

    2023.03.02

    Java 17 (17.0.5+)

    ✅

    ✅

    Java 21 (21.0.1+)

    ✅

    ✅

    Exclude methods from analysis

    ✅

    Surefire Plugin (org.apache.maven.plugins:maven-surefire-plugin)

    When using Maven and junit-jupiter-engine

    3.0.0-M7

    JUnit (junit:junit or org.junit.jupiter:junit-jupiter-engine)

    Unless using TestNG, Spring, or Spring Boot

    4.11+

    JUnit Launcher ( org.junit.platform:junit-platform-launcher)

    When using junit-jupiter-engine, unless using Maven, Spring or Spring Boot

    1+

    TestNG (org.testng:testng)

    Unless using JUnit, Spring, or Spring Boot

    Java Servlet API ( javax.servlet:javax.servlet-api or jakarta.servlet:jakarta.servlet-api)

    4+, matching version

    JSR107 API and SPI (javax.cache:cache-api)

    0.2+, matching version

    Spring Boot Starter Test ( org.springframework.boot:spring-boot-starter-test)

    2+, matching version

    Spring Security Config ( org.springframework.security:spring-security-config)

    4.2.1+, matching version

    Spring Web MVC ( org.springframework:spring-webmvc)

    5+, matching version

    Reactor Test ( io.projectreactor:reactor-test)

    3.1+

    Windows 11 Pro

    ✅

    ✅

    Windows 10 Enterprise

    ✅

    ✅

    Ubuntu 18.04

    ✅

    ✅

    RHEL 7.7

    ✅

    IntelliJ 2025.2 (Community + Ultimate)

    ✅

    latest

    IntelliJ 2025.1 (Community + Ultimate)

    ✅

    latest

    IntelliJ 2024.3 (Community + Ultimate)

    ✅

    2025.07.02

    IntelliJ 2024.2 (Community + Ultimate)

    ✅

    Open JDK

    ✅

    ✅

    Oracle JDK 8 (version 161+)

    ✅

    ✅

    Java 8 (8u351+)

    ✅

    ✅

    Java 11 (11.0.17+ - note that Java 11.0.7 is specifically NOT supported)

    ✅

    Java EE 8/Jakarta EE 8 Dependency Injection *

    ✅

    ✅

    Jakarta EE 9 Dependency Injection *

    ✅

    ✅

    Jakarta EE 10 Dependency Injection *

    ✅

    ✅

    Java 8 Projects: Spring Boot 1.3.3 to 2.7.x, Spring Core 4.1.1 to 5.3.x, Spring WebFlux 5.0.0 to 5.3.x, Spring Boot Starter WebFlux 2.0.0 to 2.7.x

    ✅

    ✅

    Java 11 Projects: Spring Boot 2.1.0 to 2.7.x, Spring Core 5.1.0 to 5.3.x, Spring WebFlux 5.1.0 to 5.3.x, Spring Boot Starter WebFlux 2.1.0 to 2.7.x

    ✅

    ✅

    Java 17 Projects: Spring Boot 2.4.0 to 3.1.x, Spring Core 5.3.1 to 6.0.x, Spring WebFlux 5.3.1 to 6.0.x, Spring Boot Starter WebFlux 2.4.0 to 3.1.x

    ✅

    ✅

    Java 21 Projects: Spring Boot 2.4.0 to 3.1.x, Spring Core 5.3.1 to 6.0.x, Spring WebFlux 5.3.1 to 6.0.x, Spring Boot Starter WebFlux 2.4.0 to 3.1.x

    ✅

    Kotlin

    ✅

    ✅

    Gradle 4.9+ (must be compatible with your version of Java).

    ✅

    ✅

    Maven 3.2.5+

    ✅

    ✅

    Ant 1.10.14+

    ✅ (requires setup)

    ✅

    JUnit 4 - 4.11 to 4.13

    ✅

    ✅

    JUnit Jupiter 5 - 5.0 to 5.12.2

    ✅

    ✅

    TestNG 6.0.1 to 7.10.2

    ✅

    ✅

    Mockito 1.9.5 - 4.11.0 for Java 8

    ✅

    ✅

    Mockito 2.22.0 - 5.20.0 for Java 11

    ✅

    ✅

    Mockito 4.1.0 - 5.20.0 for Java 17

    ✅

    ✅

    Mockito 4.1.0 - 5.20.0 for Java 21

    ✅

    JaCoCo 0.8.3+ for Java 8 and 11

    ✅

    ✅

    JaCoCo 0.8.7+ for Java 17

    ✅

    ✅

    JaCoCo 0.8.11+ for Java 21

    ✅

    ✅

    Jersey 2

    ✅

    ✅

    Jersey 3

    ✅

    ✅

    Externally via JaCoCo, SonarQube etc.

    ✅

    ✅

    Per method

    ✅

    ✅

    Per class

    ✅

    ✅

    Per package *

    ✅

    ✅

    Per module **

    ✅

    Postgres 14*

    Included

    Optional

    H2

    Included

    Preflight checks
    Maven Repository: org.springframework.boot spring-boot-starter-test 2.4.6

    6 or 7

    ✅

    2025.05.01

    ✅

    ✅

    ✅

    ✅

    Configuration options
    @Configuration
    @EnableWebFluxSecurity
    public class WebFluxTestConfig {
    @Bean
    public SecurityWebFilterChain filterChain(ServerHttpSecurity http) {
        return http.csrf().disable().build();
      }
    }
    Effective Debugging
    Optional arguments (dcover create)
    keep-partial-tests
    spring-configuration
    no-spring-tests