top of page

Java naming conventions revisited


Let's go way back to basics for a second: Java naming conventions. I wrote a post a while back regarding how to compose the name for various Java items, like classes or variables. In this post i want to emphasize the naming conventions, which relate to the use of upper/lower/camel cases when naming things.

Just as developers use these conventions when naming their code, test code needs to follow these conventions as well. Here are the things you need to consider when creating a name:

  1. package: all lower case. Example: com.imalittletester.

  2. class and interface: starts with upper case; each following word starts in upper case; all other characters are lower case. Example: WorkingWithCookiesTest.

  3. method: starts in lower case; each following word starts in upper case; all other characters are lower case. Example: deleteAllCookies().

  4. variable and parameter: starts in lower case; each following word starts in upper case; all other characters are lower case. Example: languageCookie.

  5. constant: all upper case; separation between words is done with underscore character. Example: ENGLISH_COOKIE.

These all apply to regular classes (the util or helper classes you might have in your code project) and regular methods, but also to @Test classes and @Test methods, since they are just classes and methods which have the additional @Test annotation.

If you want to make sure you managed to follow the naming conventions in your code, you could use a code analysis tool and run it on your tests. The ones i already wrote about are the Apache Maven checkstyle plugin and IntelliJ's Inspect code functionality (check that the naming conventions verification is enabled).

Recent Posts

See All

Creating an Architecture for Your Automated Tests Writing Automated Tests in Small Increments 4 Times Your Automation Passed While Bugs Were Present Now That You’ve Created Automated Tests, Run Them!

This week my newest article was released, this time on how to use Log4j to log relevant test automation information: https://blog.testproject.io/2021/05/05/logging-test-automation-information-with-log

bottom of page