Skip to main content

Code reviews rule: Inconsistent naming Apex test classes (inner classes)

Written by David Martin
Updated this week

Inconsistent naming Apex test classes (inner classes)

Why is this an issue?

Inner classes within test files should follow consistent naming conventions such as UpperCamelCase. Inconsistent naming makes code harder to read and maintain.

Examples

Example of incorrect naming:

@IsTest
public class AccountServiceTest {
private class Account_Helpers {
// Underscores break UpperCamelCase convention
}
}

Example of correct naming:

@IsTest
public class AccountServiceTest {
private class AccountHelpers {
// UpperCamelCase naming
}
}

How can I fix violations?

Rename inner classes to follow UpperCamelCase conventions:

@IsTest
public class AccountServiceTest {

private class BulkOperations {
}

@IsTest
static void testBulkInsert() {
// Test code
}
}

Configuration options

  • Pattern: Use a regular expression to define the validation pattern for inner class names.

  • Hint: Add a hint to be displayed when a detection is flagged, to give developers a tangible example of a name that suits the naming convention. The hint is not validated β€” make sure it matches your validation pattern before adding it.

When should I disable this rule?

You may dismiss specific violations when your organization uses a different naming standard that is consistently applied.

Resources

Did this answer your question?