GoogleMethodName
Since Checkstyle 13.3.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 parseXml() {}
public void Foo() {}
// violation above, 'Method name 'Foo' must start with a lowercase letter'
public void gradle_9_5_1() {}
// violation above, 'underscores only allowed between adjacent digits.'
@Test
public void login() {}
@Test
public void jdk17_0_1() {}
@Test
public void testLogin_failsGracefully12() {}
@Test
public void transferMoney_deductsFromSource() {}
@Test
public void login_fails() {}
// violation above, 'contain at least one uppercase letter for multi-segment names'
@Test
public void test_foo_1() {}
// violation above, 'underscore only allowed between letters or between digits.'
@Test
public void f$bar() {}
// violation above, 'contain only letters, digits, or underscores.'
@Test
public void test_Foo() {}
// violation above, 'Each segment must start lowercase'
}
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






