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, use the class-name-template and method-name-template options as detailed below.

Class name template

The --class-name-template="${CLASS_NAME}<string>" argument can be 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.

Usage: --class-name-template="${CLASS_NAME}<string>"

Example: --class-name-template="${CLASS_NAME}CreatedTest"

Default: ${CLASS_NAME}DiffblueTest

Method name template

The --method-name-template="<string><variable>[<variable>...]" argument can be used to define the test method naming convention for tests written by Diffblue Cover. Available variables are as follows:

  • The ${INNER_CLASS_NAME} variable will be 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.

  • The ${UNIT_NAME} variable will usually be 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.

  • The ${METHOD_NAME} variable will be substituted with the name of the first method under test, typically the only method under test.

  • The ${GIVEN} variable will be substituted with a summary of the conditions prior to the method(s) under test being called, or a blank string if no description is available.

  • The ${WHEN} variable will be substituted with a summary of the conditions when the method(s) under test are called, or a blank string if no description is available.

  • The ${THEN} variable will be substituted with a summary of the consequences the method(s) under test being called, or a blank string if no description is available.

  • The ${_} variable will be substituted with a _ separator, or a blank string if there are no values to separate.

  • To avoid duplication, do not use ${UNIT_NAME} and ${METHOD_NAME} together.

Usage: --method-name-template="<string><variable>[<variable>...]"

Example: --method-name-template="aitest${INNER_CLASS_NAME}${METHOD_NAME}"

Default: test${INNER_CLASS_NAME}${UNIT_NAME}${_}${GIVEN}${_}${WHEN}${_}${THEN}

For example, using the default naming convention for an inner class Foo with an equals(Object) and hashCode() implementation, a test method might be named testFooEqualsAndHashCode_whenOtherIsEqual_thenReturnEqual.

Disambiguation

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

@Test
public class testAppendTitle {
    ...
}

@Test
public class testAppendTitle2 {
    ...
}

Last updated