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
CoreBanking
- 7. Compile 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.
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).
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
Linux/macOS
Add the following line to your ~/.profile
(Linux) or ~/.zprofile
(macOS):
PATH=$PATH:installation_location
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.
Windows
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
Run dcover --help
to confirm that the command is found on your path and to view help information about the tool.
6. Cloning CoreBanking
The CoreBanking
application can be found at https://github.com/diffblue/CoreBanking
git clone https://github.com/diffblue/CoreBanking
7. Compile the project
Cover analyses both the source and the Java bytecode, thus the application must be compiled:
cd CoreBanking
mvn compile
8. Writing new tests
In order to create a new set of tests with dcover
use the create
subcommand.
For example, running the following command from the root of the CoreBanking
project:
dcover create
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 --test-output-dir
or -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.