Unable to achieve high code coverage using diffblue

I am currently using the trial version of the Diffblue Cover CLI. While I was able to generate test cases for a particular class in my project, I noticed that the code coverage is quite low (around 12%). This seems to be because the Diffblue-generated test cases are unable to create and test mocks properly during execution.

I have a few questions regarding this setup:

  1. The Diffblue-generated test cases use the @InjectMocks annotation from the Mockito library to create mocks, but these test cases fail to execute. Does Diffblue support the creation and testing of mock variables, especially objects used for database interactions?
  2. If Diffblue does support mock creation and testing, do I need to provide any specific datasource link to the dcover tool?

Hi @vishal

Cover does support mocking; the results will depend highly on how the code is constructed.
To address your questions

  1. The Diffblue-generated test cases use the @InjectMocks annotation from the Mockito library to create mocks, but these test cases fail to execute. Does Diffblue support the creation and testing of mock variables, especially objects used for database interactions?
  • If Cover cannot create an instance to test with, we resort to using Mock instances.
  1. If Diffblue does support mock creation and testing, do I need to provide any specific datasource link to the dcover tool?

Also, to note; you can give Cover suggestions on what object to Mock - see our guide: Mocking Annotations

I hope that answers your questions, don’t hesitate to reach out if you require further califications.

Kind regards,

Jane @ Diffblue

@Jane_Walls thank you for your support. I had another doubt.
Currently, I am working on one particular class in my project.
I am using the ‘dcover create’ command to generate test cases for that particular class and executing the test class using my custom maven test command. Following these steps, it amounts to 12 % of code coverage. How can I increase this using diffblue?

Hi @vishal

This can be a variety of reasons - the best way to see why Cover isn’t writing tests for a lot of the code is to have a look in the log file. Here you can see a summary of output codes which give reasons to why Cover hasn’t been able to write tests. It will also show any warnings in the environment which might effect Covers effectiveness.

I would be happy to have a look at your log file, and give further advice. Please upload your log file here. There is a guide on how to find the support log file; CLI / Plugin.

Kind regards,
Jane @ Diffblue