From: Eric Hodel Date: 2006-12-06T04:32:47+09:00 Subject: Re: TDD/unit testing question On Dec 5, 2006, at 06:10 , James Mead wrote: > On 05/12/06, Peter Szinek wrote: >> 1) Am I doing something wrong? (i.e. that I spend so much time with >> rewriting/modifying/updating the tests? or is this normal) >> 2) Are there some tools/methods/ideas to speed things up? Or this is >> just good so? >> 3) Maybe I am just too new to these techniques and a skilled TDDist >> marches much faster? > > - If you find that making a change to a single class is breaking loads > of seemingly unrelated tests, this is probably an indication that too > much code is being covered by each test. It may also indicate a high > level of coupling in your design. Try to keep your unit tests as > fine-grained as possible and ensure they really are black-box tests > i.e. not coupled to the implementation. Using Mock Objects in your > unit tests is a very useful technique to keep the tests as focussed as > possible. If you need to write coarser-grained tests, try to write > them against a relatively stable interface. e.g. the public API you > will expose. When I was new to TDD and unit testing this was my biggest problem, especially the coupling side. I've evolved my coding style to produce shorter, simpler methods that are easier to test (usually less than ten lines, very rarely over 25 lines). Also, I heavily refactor tests to move re-usable test code into utility methods. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!