Writing unit tests with Cover CLI

A quick guide to writing unit tests for the single-module Maven project, spring-petclinic, using the Cover CLI.

Cloning spring-petclinic

The spring-petlinic application can be found at https://github.com/spring-projects/spring-petclinic

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

Compile the project

cd spring-petclinic

mvn test-compile

Writing new tests

In order to create a new set of tests with dcover use the create subcommand.

create

For example, running the following command from the root of the spring-petclinic 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.

Example:

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 (not at the root of a multi-module project)

For additional optional arguments and examples, please refer to the Cover CLI Usage guide.

results matching ""

    No results matching ""