Open StephenWang7971 opened 10 years ago
In this discussion, I implied that, the 'assertion' should not be placed in the test method name,
In the previous practice, we have named test methods with their assertion.
Below is WHY:
Following is my PROPOSAL:
I look forward to hearing from you.
我个人认为,测试的价值体现在它是能运行的文档。基于这一点,我个人更喜欢把测试方法的命名写得像文档一样地容易阅读,所以用下划线分割单词以便看得更清楚,哪怕长一些也无妨,所以基于这一点,个人认为测试代码的命名规则可以不同于生产代码的命名规则。
Surely, I DO agree with that code should be document.
so, I'd like to put the documented test code in 'message' part of test codes.
我不会介意测试的名字比一般的方法名长一点. 不过, 太长的方法名有时也说明那个方法其实做的或者测试的东西太多了. 至于测试名字中应该包含的内容, 我个人的习惯是只说明测试的场景, 通常就是 Arrange-Act-Assert中的Arrange部分, 有时可能包含Act, 一般不会写Assert进去. 理由和洪亮上面说的差不多. 其实, 测试名字我觉得关键是表达出业务来, 不能简单罗列用例. 每个测试要清楚的告诉读者所解决的问题(就是整个问题域中的哪一部分). 然后, 关心Act和Assert内容的读者可以看具体的测试代码来了解. 最后, 我大概从来没有写过Assert中的message, 除非message包含一些assert代码无法表达的信息 (我不记得有遇到过需要写message的情况). 如果写的message表达的信息和代码重复的话, 其实也是一种重复代码.
nextTicketFromNextDispenser 没有告诉读者你想测什么。。。
More detail please. or what's your recommendation?
比如 testGetTicketsFromDifferentDispensers
This test method has a name with 92 characters.
a_new_ticket_must_have_the_turn_number_larger_than_a_dispensed_ticket_from_another_dispenser
\ max to 16 characters is an ideal way to name a java method. **
so, I proposed to name this method as :
nextTicketFromNextDispenser
Although, it has 27 characters, but it is far shorter than the original one.
What's your opinion?