[LRUG] A question on DRYness on testing methods that get / set state

Tom Stuart tom at experthuman.com
Wed Nov 23 01:02:37 PST 2011


On 23 Nov 2011, at 08:40, James Adam wrote:
> Asserting against behaviour means you're free to change the underlying implementation with reassurance that the "API" your object exposes never breaks. Comprehensive tests like those above are the price you pay for the freedom to refactor with impunity.

Seconded. Also, specifying behaviour is an essential part of driving design with your tests: you write the tests for the code you wish you had (without thinking about how it might work), then explore possible implementations to see how much freedom you have within the constraints imposed by the behavioural spec, either immediately (to get the tests passing) or later (to refactor towards deeper insight and/or greater convenience).

That's just a big-picture version of what James said, but if your tests are checking the "how" rather than the "what", they lose their leverage on the design of your implementation and eventually become a maintenance burden rather than an asset.

Cheers,
-Tom



More information about the Chat mailing list