Installation and initial setup
Implementing Diffblue Cover into your pipeline is a straightforward process. In brief, we’ll:
Find and configure the Diffblue Cover integration.
Set up a pipeline for the sample project using the GitLab pipeline editor and the Diffblue Cover pipeline template. Note that the Quick Start - General describes how to configure Diffblue Cover in CI without using the integration or pipeline template.
Create the full baseline unit test suite for a sample project.
To get familiar with setting up Cover Pipeline for GitLab on a project, we'll use the Spring PetClinic sample project here to activate and configure the Diffblue Cover integration, set up a pipeline, and write a baseline unit test suite.
eLearning
Short on time? If you'd like a fast-track experience check out our getting started video. [5 min]
1. Configure Diffblue Cover
Clone the sample project from the
https://github.com/diffblue/demo-spring-petclinic
Diffblue repo to your GitLab account.From the project in GitLab (either the sample Spring PetClinic project, or your own project) go to Settings > Integrations, find Diffblue Cover, and click Configure.
In the configuration screen, update the following (some items may be pre-selected):
Check/tick the Active box.
Enter your Diffblue Cover License key provided in your welcome email or by your organization. If needed, click the Try Diffblue Cover link to sign up for a free trial.
Enter details of your GitLab access token (Name and Secret) to allow Diffblue Cover to access your project. In general, use a GitLab Project Access Token with a
Developer
role, plusapi
andwrite_repository
scopes/permissions. If necessary you can use Group Access or Personal Access Tokens, again withapi
andwrite
permissions. See the GitLab docs links below for full details on how to create an access token.
Using an access token with excessive permissions is a security risk. If you use a Personal access token, consider creating a dedicated user with access limited to just the project, minimizing the impact of the token being leaked.
When you're done, click Save changes to apply your updates. Your Diffblue Cover integration is now Active and ready for use in your project.
2. Set up a pipeline
Here we'll create a merge request pipeline for the project that will download the latest version of Diffblue Cover, build the project, write Java unit tests for the project, and commit the changes to the branch.
From the project in GitLab go to Build > Pipeline editor and click Configure pipeline to create/edit the
.gitlab-ci.yml
file.In the editor, click Browse templates and search for the Diffblue Cover pipeline template file in the GitLab templates repo. Copy the contents of this file (sample below) to your project
.gitlab-ci.yml
pipeline file.
When using the Diffblue Cover pipeline template with your own project and existing pipeline file, add the Diffblue template content to your file and modify as needed - see Configuration for details.
When we commit these changes we'll use the commit to create a new branch and create a new merge request. So before you click Commit, update the following:
Update the Commit message with an appropriate description such as "
Update .gitlab-ci.yml file
".Update the Branch field with an appropriate name such as "
add-diffblue-cover-pipeline
".Check/tick Start a new merge request.
When you're ready, click Commit changes and go to #3.-create-the-baseline-unit-test-suite below.
For reference, an example Diffblue Cover pipeline template is shown below. Note that the version here may differ from the file provided in the GitLab templates repo.
3. Create the baseline unit test suite
On the New merge request screen, update Title with an appropriate merge request title such as
Add Cover pipeline and create baseline unit test suite
.
When you're ready, click Create merge request.
The merge request pipeline will now run Diffblue Cover to create the baseline unit test suite for the project. Once complete, go to the
src/test
folders in the project repo to see the unit tests created by Diffblue Cover (suffixed with*DiffblueTest.java
).
Subsequent code changes
When performing subsequent code changes to a project, the merge request pipeline will run Diffblue Cover but will only update the associated tests. The resulting diff can then be analyzed to check the new behavior, catch regressions, and spot any unplanned behavioral changes to the code. This workflow is illustrated further in GitLab workflow.
Next steps
This topic demonstrates some of the key features of Cover Pipeline for GitLab and how to use the integration within a pipeline. The wider and deeper functionality, provided through dcover
commands in the pipeline template, can be implemented to extend your unit test capabilities even further.
When using the Diffblue Cover pipeline template with your own project and existing pipeline file, add the Diffblue template content to your file and modify as needed - see Configuration for details. Note that only specific dcover
commands and arguments are currently supported for use with Cover Pipeline for GitLab, as detailed in Configuration.
Once you're familiar with the topics covered under Cover Pipeline for GitLab, check out the Related topics to expand your knowledge further.
Last updated