Working with assertions

Assertions need to be meaningful to be of use. To generate a meaningful assertion, i.e. one that is specific and related to the inputs in the Arrange section, please follow the example below.

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 method updateBar, then an assertion on the value of bar would be meaningful because it checks the effect of the method.

In the example above, 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. If an attempt is made to generate an assertion which is not meaningful, the Cover IntelliJ plugin warns you with a reason code of R004 ("Unable to find any meaningful assertion.")

results matching ""

    No results matching ""