Knowledge Base > DCover CLI 3.0 > Using DCover in Eclipse

Using DCover in Eclipse

Please see this YouTube video for a walkthrough of using DCover as an external tool in Eclipse. The video covers setup and test generation.

1. Download DCover CLI

Please contact Diffblue to obtain DCover CLI.

2. Prerequisites

  • Java 8 or 11 compatible source code
  • Maven projects, version 3.6 and above
  • Gradle projects, version 2.6 and above.

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 unless using Spring or Spring Boot 4.7-5.6
JUnit Launcher (org.junit.platform:junit-platform-launcher or org.apache.maven.plugins:maven-surefire-plugin) Always unless using Spring or Spring Boot 1+
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
Mockito (org.mockito:mockito-core) When using the --mock option 2.1.0 to 3.3.0

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
Java Servlet API (javax.servlet:javax.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) 5+, matching version
Spring Web MVC (org.springframework:spring-webmvc) 5+, matching version

3. Installing DCover CLI

Download the zip file from Diffblue and unzip in a suitable location:(installation_location)

  • dcover.bat - a batch script (Windows)
  • dcover - a bash script (Linux/macOS).

4. Configuring DCover CLI

  1. Go to Run > External Tools > External Tools Configuration… and enter a Name for the new configuration (e.g. DCover).
  2. Enter or browse to select the Location of the DCover executable.
  3. Enter or browse to select the Working Directory for the location of your project.

  4. Enter the following command:
create ${java_type_name} –class-name-template=$"{CLASS_NAME}Tests" –merge –skip-intermediate-test-verification –skip-test-validation –batch
create The create command for DCover
${java_type_name} The class you wish to run DCover on. This is a variable that eclipse replaces with the selected class when run.
-–class-name-template=$”{CLASS_NAME}Tests” This will change the class names so that the classes have the same names as the existing ones (provided that the existing test classes use a standard naming convention).

The quotes around {CLASS_NAME} are required so that Eclipse does not interpret this as one of its own variables.
-–merge This merges these tests with your existing classes (instead of replacing them).
-–skip-intermediate-test-verification Generates more potential tests, and saves time by not verifying them. 
-–skip-test-validation Generates more potential tests, and saves time by not validating them. 
--batch To make the output cleaner.

5. Select the option Refresh resources upon completion so that you see the new tests in your IDE once DCover has run.

5. Running DCover

  1. Select a Java class and then open it.
  2. Then click Run External Tool in the top toolbar.
  3. The DCover output is now seen in the console below.