Replies: 6 comments 3 replies
-
I looked over a bunch more test names and I think my preference is to start with the method under test (matching case) then a separator |
Beta Was this translation helpful? Give feedback.
-
The standard we've had is option 1. There might be some instances of option 3, but those are rare (I think). |
Beta Was this translation helpful? Give feedback.
-
Thanks @willr3 for raising this up 🙏 I think that option 1 and option 3 matches the Java naming convention best practices so I would tend to follow that approach, i.e., CamelCase for every method/variable. On the other hand I would not force to have a fixed pattern, |
Beta Was this translation helpful? Give feedback.
-
We all agree that Source methods encapsulate a logical process for reuse. That goal means the naming is short and descriptive of what it does. We have all seen jokes of long method names making it cumbersome to read code and there is even a code smell where long names tend to indicate too much logic is contained in a single method. Test methods ensure consistent behavior for a known input condition. I don't believe we have any re-use between the test methods so I do not believe the naming convention should adhere to the same brevity goals as source methods. I would argue the goal of naming a test method is to describe what is being tested and the test condition. For unit tests that usually means testing a target source method and describing the input conditions. the standard I think the If we decide to continue with option 1 or 3 then I worry test method names will shorten to be more readable and less descriptive of what is being tested. Perhaps option 5 so we preserve the camelCase preferences but we clearly separate the target method from the test description? |
Beta Was this translation helpful? Give feedback.
-
Yes, I agree that option 1 is redundant and only because of junit restrictions back in the day. Regarding option 5, I think it put too much restriction to what we should/shouldn't do. We have several methods that does a lot of things to mimic some sort of behavior. Some tests would fit the description of option 5, many would not. My vote would go to option 3. |
Beta Was this translation helpful? Give feedback.
-
Personally I find 1. useful for navigating unit/integration test classes to lookup a method. Starting a search with the text |
Beta Was this translation helpful? Give feedback.
-
Should we have a standard for Test method names?
test<MethodName><TestCondition>
<methodName>_<test_condition>
<methodName><TestCondition>
<methodName>_<TestCondition>
<methodName>_<testCondition>
If we decide on a standard I am personally in favor of option 2 because it copies the method name as it appears in the code (
camelCase
) and I find it easier to read the test condition insnake_case
instead of continuing theCameCase
but that only is one dev's opinion.Do we have preferences on this? Do we want to adopt a standard across tests?
Beta Was this translation helpful? Give feedback.
All reactions