Knowledge Base > IntelliJ Plugin > Test formatting

Test formatting

The format of tests produced by the 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 Diffblue Cover , and then select the Test Creation tab.

Test Styles

Under Test Formatting Options it is possible to select different “Test Styles” ( Brief, Verbose and Custom) from the drop-down list, which represent sets of options to cause the plugin to produce tests with different formatting, as described in the following sections. The example below shows the Brief style selected:


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 written with these settings might look like this:

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

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

  // Assert
  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 inlined, into the “Assert” section):

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

Custom Test Style

Changing any of the default options will switch the Test Style from Verbose or Brief to Custom.  For example, using the custom test style you can switch on and off 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:

Configuring comments in created 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);
}