Meaningful assertion

Hi, I am trying out Diffblue Cover and came across a few of these messages for methods I want tested:

Cannot generate essential test for [myMethodUnderTest]: Unable to find any meaningful assertion. Diffblue Cover could not determine valid inputs for the methods under test. Please add observers (e.g. getters or public fields) in the parameter/return class types of the method under test that access or return fields written by the method under test.

Can you explain what is a “meaningful assertion”? Why can’t Diffblue Cover find them?

A “meaningful assertion” in that error message (R004 if I’m not wrong?) is an assertion that checks the behavior of the method under test when that method is executed with the specific inputs that Cover selected for the ‘arrange’ section of the test. An assertion is “meaningful” if it is specific and related to the inputs in the arrange section.

When Cover doesn’t generate a test for a method, and instead gives you a R004, that means that it is syntactically possible to write assertions about the return value or the arguments of the method under test (otherwise it would had shown you an R003 error), but no such assertion would check anything meaningful, relevant, about the behavior exercised by the inputs.

This is best shown with an example. Would you mind sharing the signature and body of the method under test? The signatures and bodies of the classes for the return value and the parameters might be necessary as well.

For example, if you have a class like this:

public class Foo {

  int bar;
  int baz;

  public void updateBar() {
    bar += 1;


and you want to test the updateBar method then an assertion on the value of bar would be meaningful because it checks the effect of the method. On the other hand an assertion on the value of baz would not be meaningful because the value of the field is not changed by the method at all.

1 Like