From: James Mead Date: 2006-12-05T23:10:59+09:00 Subject: Re: TDD/unit testing question 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? It's difficult to give specific comments without actually seeing the codebase and tests, but here are some ideas that might help... - Don't make a big change to the code and then go through fixing loads of broken tests. This is always disheartening and makes you feel like you are spending a lot of time fixing tests. Instead break the big change down into smaller steps - make a small change to the tests and then fix the code. You should be alternating back and forth between test and code frequently. Don't get too far away from a green bar i.e. try to have as few broken tests as possible at any one time. - 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. -- James. http://blog.floehopper.org http://mocha.rubyforge.org - Mock Objects for Ruby