Over at codereview a comment hinted that using snake_case to name test methods is a good idea.
This contradicted my views and I did some research and there seem to be a lot of examples that actually use snake_case for this.
Myself, I use classic camelCase names like
testXyz for unit tests or a BDD approach
givenXyzWhenXyzThenXyz for integration tests.
There also is a third option that combines both ways, e.g.
My question is: What are good arguments for either using snake_case or camelCase to name test methods?
I'd like to start this with a few arguments from my experience and work:
In Favor of camelCase
- It follows the general Java coding conventions of using camelCase.
- It is consistent with production code.
- I personally find camelCase no harder to read than snake_case – I'm used to descriptive names from production code anyway.
- IDE support suffers when using snake_case (at least Eclipse).
In Favor of snake_case
- Some frameworks can generate reports from tests and using snake_case allows such frameworks to create correct sentences from the test names.
In Favor of a combination of both
What are other arguments? How does maybe the pattern in which the test methods are named affect the arguments?
Little disclaimer: Of course, ultimatively it comes down to team conventions. However, it might be worth discussing pros and cons for certain conventions.