Test formatting

The format of tests produced by Diffblue Cover IntelliJ Plugin can be configured via the "Test Formatting Options" within settings. Open the IntelliJ IDEA -> Preferences (macOS) or File -> Settings (Windows/Linux) menu and navigate to the Diffblue Cover option under the Tools section. Select the Generation tab.

Test Styles

Under Test Formatting Options it is possible to select different "Test Styles" (Verbose, Brief and Custom), which represent sets of options to cause the plugin to produce tests with different formatting, as described in the following sections.

Inlining Variables

"Inlining" changes the appearance of tests by removing the separate variables for the return value of the function under test and any parameters for the method call.

It is possible to configure a number of settings, under Test formatting options, which control the inlining behavior of Diffblue Cover:

Verbose Test Style

Using the Verbose Test Style, the Diffblue Cover IntelliJ Plugin creates tests containing up to three commented sections - labelled "Arrange", "Act" and "Assert". One of the tests generated with these settings might look like this:

@Test
public void testHasItem() throws Exception {
  // Arrange
  Order order = new Order();

  // Act
  boolean actual = order.hasItem();

  // Assert
  boolean resultBoolean = false;
  assertEquals(resultBoolean, actual);
}

Brief Test Style

Switching to the Brief Test Style, which is intended to produce tests in a more condensed format, the equivalent test would look like this (with the contents of the "Arrange" and "Act" sections merged, or inlined, into the "Assert" section):

  @Test
  public void testHasItem() {
    assertFalse((new Order()).hasItem());
  }

Custom Test Style

Making any manual changes to the Test Formatting Options will switch the Test Style from Verbose or Brief to Custom:

Configuring comments in generated tests

Using the Verbose Test Style, the plugin writes tests containing comments which describe each section. These comments can be hidden by unchecking the Label test sections with comments box.

If Label test sections with comments is selected, one of the tests created might look like this:

@Test
public void testHasItem() throws Exception {
  // Arrange
  Order order = new Order();

  // Act
  boolean actual = order.hasItem();

  // Assert
  boolean resultBoolean = false;
  assertEquals(resultBoolean, actual);
}

where the test is arranged into three sections (assuming no inlining options have been selected).

If Label test sections with comments is not selected, the equivalent test will look like this (all comments removed):

@Test
public void testHasItem() throws Exception {
  Order order = new Order();
  boolean actual = order.hasItem();
  boolean resultBoolean = false;
  assertEquals(resultBoolean, actual);
}

results matching ""

    No results matching ""