Getting started with DCover CLI
- 1. Download DCover CLI
- 2. Prerequisites
- 3. Installing DCover CLI
- 4. Add DCover CLI to environment search path
- 5. Check you can run DCover
- 6. Cloning
- 7. Compiling the project
- 8. Writing new tests
- 9. Next steps
A quick guide to writing unit tests for the single-module Maven example project,
CoreBanking, using the Cover CLI.
1. Download DCover CLI
Please contact Diffblue to obtain DCover CLI.
- Java 8 or 11 compatible source code (but please note that Java 11.0.7 is NOT supported)
- Maven projects, version 3.2.5 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.
For Spring projects, either:
- Use the
spring-boot-starter-testdependency to add Hamcrest
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: Maven Repository: org.springframework.boot » spring-boot-starter-test » 2.4.6. This shows that the matching version is Hamcrest 2.2 (you may have to scroll).
||Unless using Spring or Spring Boot||4.7+|
|JUnit Launcher (
||When using junit-jupiter-engine, unless using Maven, Spring or Spring Boot||1+|
|Spring Boot Test (
||When using Spring Boot (
||2+, matching version|
|Spring Test (
||When using Spring (
||4.2.5+, matching version|
||When using the
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.
|Java Servlet API (
||4+, matching version|
|JSR107 API and SPI (
||0.2+, matching version|
|Spring Boot Starter Test (
||2+, matching version|
|Spring Security Config (
||4.2.1+, matching version|
|Spring Web MVC (
||5+, matching version|
3. Installing DCover CLI
Download the zip file from Diffblue and unzip in a suitable location:(
dcover.bat- a batch script (Windows)
dcover- a bash script (Linux/macOS).
To be able to run the Cover CLI on multiple projects, add the relevant script to your path, or create an alias.
4. Add DCover CLI to environment search path
Add the following line to your
~/.profile (Linux) or
You will need to log out and in again, or reload your profile with
source ~/.(z)profile for the changes to your path to become active.
Add the DCover CLI installation location to the
PATH environment variable
Control Panel → System and Security → System → Advanced System Settings → Environment Variables
You will need to start a new shell window for the changes to your path to become active.
5. Check you can run DCover
dcover --help to confirm that the command is found on your path and to view help information about the tool.
CoreBanking application can be found at https://github.com/diffblue/CoreBanking
git clone https://github.com/diffblue/CoreBanking
7. Compiling the project
Cover analyses both the source and the Java bytecode, thus the application must be compiled:
8. Writing new tests
In order to create a new set of tests with
dcover use the
For example, running the following command from the root of the
will produce tests for all accessible functions within the project. By default, tests will be stored in files called
ClassNameDiffblueTest. If these files already exist, by default they will be replaced when the command is invoked again.
If you prefer to save the tests to a location other than
src/test/java, use the
-d option, e.g.:
dcover create --test-output-dir=src/test/diffblue
Note that, for multi-module projects, it is required to be able to compile the individual module and to run the
dcover command within the module directory rather than the root of a multi-module project.
9. Next steps
Please checkout the knowledge base for more guides, videos and information.