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:
- package: all lower case. Example: com.imalittletester.
- class and interface: starts with upper case; each following word starts in upper case; all other characters are lower case. Example: WorkingWithCookiesTest.
- method: starts in lower case; each following word starts in upper case; all other characters are lower case. Example: deleteAllCookies().
- variable and parameter: starts in lower case; each following word starts in upper case; all other characters are lower case. Example: languageCookie.
- 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).