Links

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 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.

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

Cover Plugin and Cover CLI are provided as part of the free trial. This topic 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 is not part of the free trial - if you'd like to discuss this Diffblue Cover feature please contact us.

1. Sign up

If you haven't already done so, sign up for the free trial - see https://www.diffblue.com/try-cover.
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

From IntelliJ IDE
From a ZIP Archive
  1. 1.
    In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).
  2. 2.
    Select the Marketplace tab, search for Diffblue, and click Install. Your plugin will now be downloaded and installed.
  3. 3.
    When prompted, click Restart IDE to complete the install.
  1. 1.
    Download the Diffblue Cover Plugin for IntelliJ as a .zip bundle from: - The Diffblue website - Free Community Edition or Free Trial versions. - The JetBrains Marketplace (IntelliJ Plugin Marketplace). - The link sent to you via your Diffblue Cover welcome email. - Your organization's internal file/app store.\
  2. 2.
    In the IntelliJ IDE, open the Plugins menu - either File > Settings > Plugins (Windows/Linux) or IntelliJ IDEA > Preferences > Plugins (macOS).
  3. 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. 4.
    When prompted, click Restart IDE to complete the install.

3. Install Cover CLI

Windows
Linux/macOS
  1. 1.
    Download the Diffblue Cover CLI .exe installer or .zip file from: - The Diffblue website - Free Trial version. - The link sent to you via your Diffblue Cover welcome email. - Your organization's internal file/app store.\
  2. 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. 3.
    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.
  4. 4.
    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. 1.
    Download the Diffblue Cover CLI .zip file from: - The Diffblue website - Free Trial version. - The link sent to you via your Diffblue Cover welcome email. - Your organization's internal file/app store.\
  2. 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:\
    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. 3.
    Once complete, run dcover version to check the install and PATH configuration - if all is OK, Cover will display the current version.

4. Apply licenses

Cover Plugin
Cover CLI
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 Licensing. Note that:
  • Applying a license provides access to the Teams and Enterprise Editions of Diffblue Cover. The free Community Edition does not require a license.
  • Offline license activation is available with the Diffblue Cover Enterprise Edition only. This can only be done through the CLI.
  • See Cover Editions or 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 XXXX-XXXX-XXXX-XXXX - replace XXXX-XXXX-XXXX-XXXX 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

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:
Git CLI
IntelliJ UI
  1. 1.
    Open a command line and navigate to where you want to clone this project.
  2. 2.
    Run the following command:
git clone https://github.com/diffblue/demo-spring-petclinic
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.

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:
cd demo-spring-petclinic
./mvnw package
Basic prerequisites:
  • Java 8, 11, or 17 compatible 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 Specs & Reqs. 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) Output Codes.
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:
cd demo-spring-petclinic
dcover create --preflight

Step 3 - A few basics

Before we start using Diffblue Cover to write tests, it's worth covering a few basics first.
Cover Plugin
Cover CLI
We won't cover the whole UI here, but here are a few useful gutter icons to get you started:
Icon
Description
Indexing - Diffblue Cover is discovering your project structure.
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 writing in progress - please wait while Diffblue Cover writes tests for your method or class.
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 <lic-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 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 Commands & Arguments for details.

First we'll use Cover Plugin for IntelliJ:
  1. 1.
    In IntelliJ, open the PetClinic project and navigate to a class - for example, OwnerController.
  2. 2.
    To create tests for this class, click on the
    Write Tests gutter icon next to the line class OwnerController.
  3. 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 folder for the project.
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"));
}
....

Now we'll move on to using Cover CLI.
  1. 1.
    Open a command line or open the ItelliJ terminal, and navigate to the demo-spring-petclinic folder.
  2. 2.
    Enter the following command to write tests for the PetController class:
dcover create org.springframework.samples.petclinic.owner.PetController
  1. 3.
    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.
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();
}
....
  1. 4.
    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?

  1. 1.
    Diffblue Cover first ensures that your code is compiled. This is required because Cover analyses the bytecode to fully understand your application.
  2. 2.
    Then Cover triggers an execution of all possible paths through each method that Cover will create tests for, and any related methods. It uses inputs that are similar to those a developer would choose and determines the most useful assertions to add to the tests (the assertions always reflect the current behavior of the code).
  3. 3.
    Finally the best test candidate is committed for each method. The tests are computationally perfect and human readable, every time.

Next steps

Now you're up and running with Diffblue Cover:
  • 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 pre-requisites, you're literally a click away from AI written tests, created in seconds instead of hours.
  • See Cover Plugin and Cover CLI 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.