Getting started with the Diffblue Cover IntelliJ plugin

A quick guide to writing unit tests for a demonstration project, using the Diffblue Cover IntelliJ plugin.

1. Download Cover IntelliJ plugin

Please contact Diffblue to obtain the Cover IntelliJ plugin.

2. Prerequisites

  • IntelliJ version 2019.3
  • Java 8 compatible source code
  • Maven or Gradle-based project

Dependencies required for running tests should be in the project configuration. JUnit is always mandatory but other libraries may also be necessary depending on the project under test.

Dependency When Version
JUnit (junit:junit or org.junit.jupiter:junit-jupiter-engine) Always 4.7-5.6
Spring Boot Test (org.springframework:spring-boot-test) when using Spring Boot (org.springframework:spring-boot) 2+, matching version
Spring Test (org.springframework:spring-test) when using Spring (org.springframework:spring-core) unless using Spring Boot 5+, matching 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 Event Log indicating a missing dependency.

Dependency Version
Java Servlet API (javax.servlet:javax.servlet-api) 4+, matching version
Spring Boot Starter Test (org.springframework.boot:spring-boot-starter-test) 2+, matching version
Spring Security Config ( 5+, matching version
Spring Web MVC (org.springframework:spring-webmvc) 5+, matching version

3. Installing Cover IntelliJ Plugin

Download the zip file to a suitable location.

From the IntelliJ IntelliJ IDEA -> Preferences (macOS) or File -> Settings (Windows/Linux) menu, select the Plugins item.

Click on the cog-wheel icon to the right of the Installed tab at the top of the window. From the drop-down menu, select Install Plugin from Disk...

Navigate to the location of the plugin, select the zip file, and then click Open. Click OK.

When prompted to do so, click to Restart IDE, and then click OK.

4. Importing CoreBanking

The CoreBanking application is a simple banking application for demo purposes which can be found at

Start IntelliJ without a project loaded to see the welcome screen:

Choose the Get from Version Control option. Select Git from the Version control dropdown box. Enter the CoreBanking url into the repository box, selecting an appropriate location for the project. Then, click Clone.

Once it has been successfully cloned, expand the CoreBanking section under Project to see the source tree.

5. Writing new tests

In order to generate new tests for a class which is not currently covered:

  1. Select the Project window.
  2. Select CoreBanking->src->main->java->io.diffblue.corebanking->account->Account.
  3. Right-click and select the Write Tests option from the menu.

The plugin builds the project before analyzing the code and creating the tests. Once the project has been built, click the progress bar at the bottom of the screen to open a pop-up window.

The progress window will show the different stages that the analysis is going through. While the code is being analyzed, it is possible to view the current progress, but in smaller projects, such as CoreBanking, this is a very short time-frame.

Once the new tests have been created, they will be automatically integrated into the project under src/test/java.

* Note that it is also possible to Write Tests by right-clicking the following:

  • Individual classes from within the source editor
  • Individual methods from within the source editor
  • Individual classes from the tab at the top of the source file
  • Individual methods from within their classes in the Project menu (if Show Members has been selected after right-clicking on the Project menu)

Elsewhere within the IDE, for example in test classes or non-Java files, the Write Tests feature is disabled.

6. Running the tests

After Diffblue Cover has written tests for your project, they will be automatically integrated into your test suite. Tests created by Diffblue Cover make use of the JUnit testing framework so junit is included in the CoreBanking project dependencies in the pom.xml.

In project explorer, select the new class from CoreBanking->src->test->java->io.diffblue.corebanking->AccountTest, then right-click and select Run 'AccountTest'.

This will then show the results of the JUnit run:

7. Next steps

Please checkout the knowledge base for more guides, videos and information.

results matching ""

    No results matching ""