nondet-static

Allows Diffblue Cover to analyse code by choosing different values for static class fields.

Description

Diffblue Cover will construct method arguments and instance fields to provide coverage for each line. By default, static class fields are not part of this set of inputs and only the values which these fields are initialized with are considered. Therefore if this code is given to Diffblue Cover:

public class Test {

  static int staticVar = 3;

  public static int func() {
    if (staticVar == 2) {
      return 1;
    }
    return 0;
  }
}

The return 1 line will not be covered, because staticVar is considered to be invariably 3. The nondet-static option tells Diffblue Cover to consider static fields as inputs, so it may now produce whatever value is necessary to cover the missing line (in this case: 2).

Usage

Using the nondet-static option can be useful to cover lines that are otherwise unreachable. However, its general usage is not recommended. This is because it may produce test cases that are of poorer quality; altering static fields can be seen as bad practice, and is often unnecessary. Modifying a static field also implies that these fields must be reset to their original value at the end of the test in order to not influence the execution of subsequent tests. Due to this, nondet-static will make generated tests more verbose.

phases:
-
  cbmcArguments:
    nondet-static: true

Default

Phase Default
1 false
2 false
3 false

results matching ""

    No results matching ""