Closed wey1and closed 3 years ago
Thank you for the proposal!
I suggest using only test_
for method prefixes instead of some names, the test method name already includes the "shouldSomething" part which describes it.
Thank you for the proposal!
I suggest using only
test_
for method prefixes instead of some names, the test method name already includes the "shouldSomething" part which describes it.
Done
I'll try to finalize the agreement:
1 Name of test method must not violate linter rules and generate compiler warnings (must not contain special characters, be longer than 120 chars etc).
2 These points of testcase must be readable and simple:
It's good when they can be included into test method name but it's not always possible. When the description is too large then testcase should contain a comment on points mentioned above.
3 Do not perform a total refactoring of existing codebase. Just leave the code better than it was after making changes.
Also maybe use this pattern ?
@akudiyar @wey1and
test_[method]_when[condition]_then[reaction]
For example:
test_helloWorld_whenCalled_ThenPrintHelloWorld()
instead of this
test_[methodName/scenarioName]_should[Action]_if[Condition]
[methodName/scenarioName]_ - is optional.
if[Condition] - is optional. You can omit this if the execution is straightforward.
Thanks to all! Based on the discussion, I brought the initial version to the final one.
I suggest the following convention: Tests names should be correspond the next pattern:
test_[methodName/scenarioName]_should[Action]_if[Condition]
[methodName/scenarioName]_ - is optional. if[Condition] - is optional. You can omit this if the execution is straightforward.
Also, inside the body of the test there should be comments of the following format:
Example: If we have method like this:
Test for this method:
If we have method like this:
Test for this method can be like this:
It's good when this pattern can be included into test method name but it's not always possible. When the description is too large then test case can contain additional info in comment. Also consider this points: