# Test Naming

Test classes and methods created by Diffblue Cover are named after the class and methods under test using configurable templates. To change the naming, go to `Diffblue > Change Settings` in IntelliJ and update the `Test Naming` section as needed.

<figure><img src="/files/w6N4mrO1MgltiFT6PghG" alt=""><figcaption></figcaption></figure>

## Class Name Template

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

**Default:** `${CLASS}DiffblueTest`

**Example:** `${CLASS}CreatedTest`

```java
public class UserAccessCreatedTest {

    public String currentUser;

    ...
}
```

{% hint style="info" %}
Merge mode is enabled by default in the IntelliJ plugin. However, the default template `${CLASS}DiffblueTest` keeps generated tests in separate files.

To take advantage of merge mode, change the class name template to match your existing test naming conventions (e.g., `${CLASS}Test`). This allows generated tests to merge into your existing test classes.

See [Merge Mode](/features/cover-cli/writing-tests/merge-mode.md) for more information about merge mode.
{% endhint %}

## 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}` - 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}` - 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}` - substituted with the name of the first method under test, typically the only method under test. To avoid duplication, do not use `${UNIT}` and `${METHOD}` together.
* `${GIVEN}` - substituted with a summary of the conditions before testing, or else blank.
* `${WHEN}` - substituted with a summary of the conditions under test, or else blank.
* `${THEN}` - substituted with a summary of the test's consequences, or else blank.
* `${_}` - substituted with an underscore, or blank if there are no values to separate.

**Default:** `test${INNER}${UNIT}${_}${GIVEN}${_}${WHEN}${_}${THEN}`

**Example:** `aitest${INNER}${UNIT}`

```java
@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());
}
```

## Descriptive Test Names

Descriptive `${GIVEN}` , `${WHEN}` and `${THEN}` summaries are populated when disambiguating multiple tests for the same method under test, and are added to the test method name up to a maximum of 80 characters. When descriptive test names are enabled they are additionally used to provide improved javadoc comments, and to provider clearer test display names when the test framework supports it.

```java
/**
 * Test {@link BaseEntity#isNew()}; given BaseEntity Id one; then returns false.
 * <p>
 * Method under test: {@link BaseEntity#isNew()}
 */
@Test
@DisplayName("Test isNew(); given BaseEntity Id one; then returns false")
void testIsNew_givenBaseEntityIdOne_thenReturnsFalse() {
	// Arrange
	BaseEntity baseEntity = new BaseEntity();
	baseEntity.setId(1);

	// Act and Assert
	assertFalse(baseEntity.isNew());
}

/**
 * Test {@link BaseEntity#isNew()}; given BaseEntity; then returns true.
 * <p>
 * Method under test: {@link BaseEntity#isNew()}
 */
@Test
@DisplayName("Test isNew(); given BaseEntity; then returns true")
void testIsNew_givenBaseEntity_thenReturnsTrue() {
	// Arrange, Act and Assert
	assertTrue((new BaseEntity()).isNew());
}
```

When `${UNIT}` is describes a single method under test that has overloads then the method under test's arguments are additionally described.

```java
/**
 * Test {@link Owner#getPet(String)} with name.
 * <p>
 * Method under test: {@link Owner#getPet(String)}
 */
@Test
@DisplayName("Test getPet(String) with name")
void testGetPetWithName() {
	// Arrange, Act and Assert
	assertNull((new Owner()).getPet("Bella"));
}

/**
 * Test {@link Owner#getPet(String, boolean)} with name, ignoreNew.
 * <p>
 * Method under test: {@link Owner#getPet(String, boolean)}
 */
@Test
@DisplayName("Test getPet(String,boolean) with name, ignoreNew")
void testGetPetWithNameIgnoreNew() {
	// Arrange, Act and Assert
	assertNull((new Owner()).getPet("Bella", true));
}
```

Descriptive test names are enabled by default but can be disabled via the "Descriptive Test Names" setting.

## Numeric Disambiguation

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

```java
@Test
public void testAppendTitle() {
    ...
}

@Test
public void testAppendTitle2() {
    ...
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cover-docs-preview.diffblue.com/features/cover-plugin/cover-plugin-settings/test-naming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
