GoogleMethodName
Since Checkstyle 13.1.0
Description
Checks that method names conform to the
Google Java Style Guide for method naming.
This check enforces Google's specific method naming requirements:
- Method names must start with a lowercase letter and use uppercase letters for word boundaries.
- Underscores may appear in JUnit test method names to separate logical components.
- Underscores may be used to separate adjacent numbers (e.g., version
numbers like
guava33_4_5), but NOT between letters and digits.
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="GoogleMethodName"/>
</module>
</module>
Code Example:
class Example1 {
public void fooBar() {}
public void guava33_4_5() {}
public void Foo() {}
// violation above, 'Method name 'Foo' must start with a lowercase letter'
public void gradle_9_5_1() {}
// violation above, ''gradle_9_5_1' has invalid underscore usage'
@Test
public void login_fails() {}
@Test
public void test_foo_1() {}
// violation above, ''test_foo_1' has invalid underscore usage'
}
Example of Usage
Violation Messages
- google.method.name.format.regular
- google.method.name.format.test
- google.method.name.underscore.regular
- google.method.name.underscore.test
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks.naming






