How to populate collections?

Hi, I wanted to know how to configure Cover so I can populate collections. Right now the plugin is creating empty arrays so there are parts of the code that are not being covered (for eachs, for example). Thank you!

Hi @edominguez ,

Thank you for reaching out - for context, Cover supports Java Collections, so should attempt to populate them for a test. In your case; it may not have been able to because of the complexity of the code or the type of objects it had to construct to create the Collection.
First, I would recommend ensuring you have the most up to date version of Cover by checking your market place in IntelliJ (note; we support the last 2 versions of IntelliJ) .
If you are up to date already, there are 2 ways to solve this:

  1. (Recommended) Use the Custom Test Set-up feature to give Cover a relevant populated Collection
    • Here you can construct the Collection yourself, then Cover should then that to write the tests (including your for-each).
    • See the guide here for full instructions.
  2. (Alternative) Find the reason why Cover isn’t able to populate your Collection via output codes
    • When Cover is unable to write a test, it will provide an output code which gives a reason why it might have struggled. This information can be found in the log file, guide to find the log file here: CLI / Plugin.
    • This will give you some indicators about how to get round this, likely by making changes to the code to make it more testable.

I recommend option 1 here as this is likely to be more efficient and get a better result, because you can construct a Collection that is most relevant with your program. Option 2 is likely going to be trickier and will heavily depend on what issue Cover is having with the code.

I hope this helps, please let me know if you have any questions!

Kind regards,
Jane @ Diffblue