Featured post
java - Prefix for testing methods in Unit: "test" vs "should" -
it common practice prefix tests method names in junit "test". in last few years, people changed prefix "should".
if want test customer creation in database, name method "testcustomercreation". however, people name "shouldcreatecustomer".
this lot of personal taste when person in project or when else in project agrees me. when/where not case, divergences or inconsistent mixes starts shows up.
i readed somewhere article of guy named methods "testshouldcreatecustomer", , reason decided drop "test" prefix. in fact wasn't prefixing "test", using "testshould" , changed "should". obviously, did not convinced me.
i inclined stick "test" prefix because methods names starts verbs in infinitive form ("get", "set", "add", "remove", "clear", "send", "receive", "open", "close", "read", "write", "create", "list", "pop", "print", etc, "test"). so, prefixing method name "should" makes sound strange me, looks wrong.
so, real reason use "should" instead of "test"? great advantages , disadvantages?
the 'should' convention aligned behaviour driven development style of testing.
i prefer write tests in style, encourages write tests read specifications, , more aligned behaviour of class or system testing.
where possible, go 1 step further , give test class more context using it's name:
class anewlycreatedaccount { shouldhaveazerobalance() {} shouldcalculateitsowninterest() {} }
by naming classes , thinking them in specification style, can give lot of guidance on which tests write, , in order should write tests , make them green.
yes, 'should' vs 'test' prefix , it's important consistent, question style , mindset of how test code , choose tests write. bdd has ton of value, suggest reading further , give try.
- Get link
- X
- Other Apps
Comments
Post a Comment