Module 1: Create your Cover unit test baseline

In this module, we will enable you to perform the first steps of onboarding a new project. These are:

  1. make your first projects Cover-ready by validating the build configuration with respect to unit testing, and

  2. write a test baseline for your first projects

Prerequisites

To start this module, you need to satisfy the prerequisites, which amount to having Cover installed at least to the level of Reference Deployment 1, i.e.

  • Cover Reports is installed on a central server.

  • As a champion you have Cover CLI installed in a development environment that satisfies the requirements.

  • You have run preflight and sent the log files to Diffblue.

License activation

Activate Cover CLI using the license key that you received from the contact for software and license distribution in your organization:

dcover activate XXXX-XXXX-XXXX-XXXX

View your license details to check that the activation was successful:

dcover license

Telemetry configuration

We will check that telemetry is correctly configured on your system.

Usage information is sent to

  • External Diffblue telemetry server (Enterprise Edition users can opt out)

  • Cover Reports (if configured)

Telemetry is configured via one of

  • ~/.diffblue/telemetry.properties, or

  • Environment variables

Check that:

  • External telemetry is configured according to your company policies.

  • Cover Reports telemetry points to your central Cover Reports server.

Make your project Cover-ready

We will work through the whole flow for creating baseline tests.

You can find a worked example of the entire flow here.

If your project has multiple modules we recommend that you start with a representative module. Once the selected module is working, repeat the steps on the other modules.

Note that you can run a specific module without changing your working directory by adding the following option to the dcover commands: --working-directory your-selected-module

We will start with the validation of your build configuration - and fixing it if necessary. We will also measure and upload your existing unit test coverage.

Create your unit test baseline

We are now ready to create the baseline tests.

What does Cover CLI do?

When running a Cover command, the execution proceeds in several phases.

Understanding Cover's log output

Cover produces output with increasing degree of detail:

The log files are in the .diffblue/log directory below the directory from where Cover was run.

Overview of CLI options

The following is a short list of the more pertinent options for creating baseline tests. Details of additional options can be found in the Commands & Arguments.

Cover automatically figures out which entry point methods to write tests for. The set of methods can be restricted by specifying inclusions and exclusions. E.g. to write tests only for the OwnerController class you can run dcover create org.springframework.samples.petclinic.owner.OwnerController

What does Cover do during test generation?

To generate tests, Cover analyzes your project's bytecode. It runs your code, and thus operates in a sandbox. The sandbox runs in a separate service process which prohibits system calls (file system, network, etc) to protect your system from potentially detrimental functionality within your codebase (e.g. wiping your filesystem, spamming third party services).

Cover partitions your code into groups of methods under test that it is going to test. For each group of methods under test, Cover

  • either produces tests

  • or an output code that explains why it didn’t produce complete tests

Understanding Cover's output codes

Output codes identify the messages that Cover outputs, e.g. E052 - Missing dependency

The output code can be used to quickly look it up in docs: e.g. https://diff.blue/E052

There are different types of messages distinguished by the first letter in the output code:

  • Informational messages:

    • Testability (T), reason for not writing tests (R)

  • Warnings/errors:

    • Project environment (E) including coverage measurement and reports upload

    • Licensing (L)

What does test validation do?

Validation ensures that generated tests compile and pass. This is essential for Cover's autonomous operation in your CI Pipeline.

You may see two output codes related to test validation:

  • First, tests are compiled and run individually (W output code).

  • Finally, tests are run via your build system (V output code).

Coverage measurement

Cover uses JaCoCo for coverage measurement.

Cover distinguishes two types of tests:

  • Diffblue-controlled tests (“Diffblue”)

    • Unchanged tests written by Cover

    • Automatically maintained by CI pipeline

  • User-controlled tests (“manual”)

    • Manually written or modified Diffblue tests

    • Maintained by user

    • These include the existing tests that you have manually written before starting to use Cover.

How to ask for support

Before reaching out, check for potential solutions in

More complex questions & issues contact support depending on your support plan.

Requirements for Diffblue to handle your support case:

  • Detailed description of what you did and the behavior you observe (compared with what you expect)

    • Diffblue Cover support log file

    • Additionally, for R code-related questions, one of the following:

      • A reproducer (most valuable to be able to support): a piece of code that results in the the R code message that you see

      • A code snippet of the relevant code under test (useful, but with lower chances of success) and a partial test (if there is one) with the R code

Worked example: Baseline creation process using the Petclinic demo project

The prerequisites for running this example are:

We will work through the whole flow for creating baseline tests.

Last updated