Test Naming

By default, test classes created by Diffblue Cover are named <CLASS_NAME>DiffblueTest and test methods are named test<INNER_CLASS_NAME><UNIT_NAME>. To change the naming, go to Diffblue > Change Settings in IntelliJ and update the Test Naming section as needed (using string literals and replacements).

Class name template

Description: Used to define the test class naming convention for tests written by Diffblue Cover. The ${CLASS_NAME} variable will be substituted with the name of the class under test.

Default: ${CLASS_NAME}DiffblueTest

Note that if the default class naming convention is not used, there will be no distinction between Diffblue Cover tests and manual tests in Cover Reports.

Example: ${CLASS_NAME}Test

public class UserAccessTest {

    public String currentUser;

    ...
}

Method name template

Description: Used to define the test method naming convention for tests written by Diffblue Cover. The following variables can be used:

  • ${INNER_CLASS_NAME} - substituted with the name of the inner class for the method under test. If there's no inner class this will be an empty string.

  • ${UNIT_NAME} - usually substituted with the name of the method under test. Where the unit under test comprises multiple methods (getters and setters, equals and hash code) the more general unit under test name is used.

  • ${METHOD_NAME} - substituted with the name of the first method under test, typically the only method under test.

  • Use ${UNIT_NAME} or ${METHOD_NAME} to include the method name in the test name, but to avoid duplication don't use both together.

Default: test${INNER_CLASS_NAME}${UNIT_NAME}

Example: aitest${INNER_CLASS_NAME}${UNIT_NAME}

@Test
public void aitestGettersAndSetters() {
    // Arrange
    ComponentPojo componentPojo = new ComponentPojo();

    // Act
    componentPojo.setName("Name");
    componentPojo.setSize(3);
    String actualName = componentPojo.getName();
    // Assert that nothing has changed
    assertEquals("Name", actualName);
    assertEquals(3, componentPojo.getSize());
}

@Test
public void aitestEqualsAndHashCode() {
    // Arrange
    DoubleArgumentType doubleArgResult = DoubleArgumentType.doubleArg(10.0d, 10.0d);

    // Act and Assert
    assertEquals(doubleArgResult, doubleArgResult);
    int expectedHashCodeResult = doubleArgResult.hashCode();
    assertEquals(expectedHashCodeResult, doubleArgResult.hashCode());
}

Disambiguation

Disambiguation between tests of the same name is performed automatically using sequential numbering:

@Test
public class testAppendTitle {
    ...
}

@Test
public class testAppendTitle2 {
    ...
}

Last updated