Reputation: 129
What is the proper naming convention for java junits test methods.
public void testServiceName_NullValue() or public void testServiceName_nullValue()
any suggestions ?
Thanks
Upvotes: 1
Views: 9838
Reputation: 1130
I haven't seen a standard, unlike general coding (e.g. Google's). In my team, though, we decided that the test name should very clearly tell what it does even if the resulting name is much longer than the usual method name. The resulting names won't be too long in the end, because a test should focus on one and only one thing. Otherwise, you should rethink your test's scope or your unit's design.
Concretely, we tend to follow the convention if/whenConditionThenExpectedState/Behavior. We omit the test prefix which today is unnecessary and doesn't add value to the name.
Upvotes: 6