unit testing - Spock - @Subject annotation and util | helper class that's being tested -
i got question regarding convention of tests in spock.
let got a class test, util class static methods. classic way test it, a.method() in each test method.
however, in spock got @subject annotation (and groovy let that, if said class has private constructor) , began wondering.
@subject util = new a() and later in tests call methods util.method().
by doing that, achieve cleaner test. instantly see what's being tested. in ides highlighted , so. @subject verbose annotation.
do see cons of doing tests such way? or there better way clealny test util classes in spock?
i see advantage of having verbose @subject, instantiating utility class can cause more confusion.
there check intellij instantiation of utility class:
reports new expressions instantiate utility classes. utility classes have fields , methods declared static, , presence may indicate lack of object-oriented design. instantiation of such classes indicates programmer error.
- it's unnatural , might considered programming mistake other developers
- disobeying
privatekeyword bad practice - sonar, codenarc , intellij complain
i go classic approach or avoiding utility classes @ all. it's convention though.
Comments
Post a Comment