Cover not creating Tests with the IntelliJ Community Edition

Hello

I am new to the Diffblue Cover plug-in in Intellij Community Edition IDE.

For a simple Employee class it is complaining as listed below- have I missed something?

Creating tests for method: Employee.

16:37 Cannot generate essential test for : Nothing to assert: the constructed class does not have observers (e.g. getters or public fields). Add observers (e.g. getters or public fields) to the class.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.setId

16:37 Cannot generate essential test for setId: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.toString

16:37 Cannot generate essential test for toString: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.getDepartment

16:37 Cannot generate essential test for getDepartment: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.main

16:37 Cannot generate essential test for main: Nothing to assert: neither the return value type of the method under test nor the types of its parameters have observers (e.g. getters or public fields). Add observers (e.g. getters or public fields) to the declaring class of the method under test, its return type or any of its parameter types.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.setAge

16:37 Cannot generate essential test for setAge: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.setDepartment

16:37 Cannot generate essential test for setDepartment: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.

16:37 Cannot generate essential test for : Nothing to assert: the constructed class does not have observers (e.g. getters or public fields). Add observers (e.g. getters or public fields) to the class.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.

16:37 Cannot generate essential test for : Nothing to assert: the constructed class does not have observers (e.g. getters or public fields). Add observers (e.g. getters or public fields) to the class.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.getId

16:37 Cannot generate essential test for getId: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.getName

16:37 Cannot generate essential test for getName: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.getAge

16:37 Cannot generate essential test for getAge: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Creating tests for method: Employee.setName

16:37 Cannot generate essential test for setName: Unable to instantiate class containing the method under test. Please provide a package-visible constructor or factory method for testing which (ideally) takes no arguments, and does not throw, return null or return a subtype.

16:37 No tests have been generated: Cover was unable to generate any tests for your selection. Please refer to the documentation for further assistance.

16:37 Test creation complete: Created 0 tests in total for 0 methods from 0 source classes

Hi!
Looking at the error messages you get, could you possibly share the Employee class? It seems Cover has trouble instantiating the class - this can be due to a variety of reasons (constructor and factory methods not visible, constructor/factory throws an exception for all inputs that we try, and some more obscure cases).

Alternatively, can you have a look at the log files (on Linux, they’d be in /tmp/diffblue/log/cover-plugin-analysis.log and /tmp/diffblue/log/cover-plugin.log; the locations on other platforms should be in the manual)? They may contain more details information about what exactly caused the failure.

I restarted IntelliJ and was able to create tests.

It has created tests for the setXXX() methods only.

Hi,
very good that you get tests now.
I see that your class has only setters, getters and a main method.
We don’t write a test for the main method because there aren’t any effects of that method that could be asserted in a unit test. The constructor and getters are tested as part of the setter tests. That’s why you only see tests for the setters.
If you want to have a test for the logic in the main method then you need to factor out that logic into a separate method which also allows its effects to be observed in a test. For example, you could return the result that you want to be verified by the test as return value of that new method.

1 Like

Thanks Peter. That is helpful. The class that I created is very basic and just to get started with Cover.