Getting started with JCover

Diffblue’s JCover is a command-line tool for automatically generating unit tests for Java code, which can be easily incorporated into your existing Continuous Integration (CI) framework to catch software regressions before they reach production source.



1. Download JCover

Please contact Diffblue to obtain JCover.

2. Prerequisites

2.1 Software Prerequisites

  • JDK 6 - 14 (Please note: a JRE is insufficent)
  • JUnit 3.7 - 5 or TestNG 4.4.7 - 7.1.0
  • Maven 3.6+, Gradle or Ant

2.2 Dependencies

Dependency When Version
JUnit (junit:junit or org.junit.jupiter:junit-jupiter-engine) When using JUnit 3.7
Spring Boot Test (org.springframework:spring-boot-test) when using Spring Boot (org.springframework:spring-boot) 1+ or 2+, matching version
Spring Test (org.springframework:spring-test) when using Spring (org.springframework:spring-core) unless using Spring Boot 4+ or 5+, matching version

Add any required dependencies to your Maven (pom.xml) or Gradle (build.gradle) config file, as below:

JUnit: https://mvnrepository.com/artifact/junit/junit

TestNG: https://mvnrepository.com/artifact/org.testng/testng

3. Installing JCover

Select the relevant installation options from the selection below:

3.1 Installing JCover on Linux from a zip file

Unzip the file into its own folder installation_location.

Edit the ~/.profile file and add the installation_location to your search path, e.g.

PATH=$PATH:installation_location

Then, reload the profile file to make your changes active (or log out and in again):

$ source ~/.profile


3.2 Installing JCover on macOS from a zip file

Unzip the file into its own folder installation_location.

Edit the ~/.zprofile file and add the installation_location to your search path, e.g.

PATH=$PATH:installation_location

Then, reload the profile file to make your changes active (or log out and in again):

$ source ~/.zprofile


3.3 Installing JCover on Windows 10 from a zip file

Unzip the file into its own folder installation_location.

Access the environment variables:

Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables

If JAVA_HOME and JCOVER_HOME do not already exist, set them up as follows:

JAVA_HOME as the location of your JDK

JCOVER_HOME as the installation_location

Finally, add %JCOVER_HOME%to your PATH environment variable.


3.4 Installing JCover on Debian-based Linux (e.g. Ubuntu)

Run the following commands in a terminal window, replacing "version" with the actual version number:

$ sudo apt-get update

$ sudo apt remove jcover (if another version is already installed) $ sudo apt install ./jcover_version.deb


3.5 Installing JCover on Fedora-based Linux

Run either of the following commands in a terminal window, replacing "version" with the actual version number:

$ sudo yum install ./jcover-version.rpm

or

$ sudo dnf -y install ./jcover-version.rpm

4. Check you can run JCover

To check your installation is complete, enter the following command in a terminal window:

$ jcover --version

(make sure the version number matches the expected value)

For usage and option information, enter:

$ jcover --help

5. Writing unit tests with JCover using Maven

5.1 Starting to write unit tests

A sample Spring Boot project, called sprint-petclinic, has been created so you can easily start writing unit tests with JCover.

To clone the Spring-Petclinic project:

git clone https://github.com/spring-projects/spring-petclinic

$ cd spring-petclinic


To build the project, use either:

$./mvnw install (Linux/macOS)

> mvnw install (Windows)


To create tests for the project:

jcover --test-verification --spring-format --class-suffix DiffblueTest

6. Next steps

Please checkout the knowledge base for more guides and further information.

results matching ""

    No results matching ""