Test formatting
The format of tests produced by Cover Plugin for IntelliJ can be configured via the "Test Formatting Options" within settings.
The format of tests produced by Cover Plugin for IntelliJ can be configured via the "Test Formatting Options" within settings. In IntelliJ go to
IntelliJ IDEA > Preferences > Diffblue Cover > Test Creation
(macOS) or File > Settings > Diffblue Cover > Test Creation
(Windows/Linux).It's important to note that the formatting of tests produced by the Cover Plugin for IntelliJ, especially regarding indentation and other style settings, is in line with your current IntelliJ formatting configurations. This ensures that the generated tests adhere to the code style settings you've set up in your IDE. If you experience formatting conflicts with other tools, such as Spotless, you might need to align your IntelliJ formatting settings with those tools to maintain consistency.
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:
Using the
Verbose
Test Style, Cover Plugin for IntelliJ 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);
}
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());
}
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: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);
}
Last modified 23h ago