开发者

TDD and Responsibility Driven Design - how to reconcile test-first with the design process?

开发者 https://www.devze.com 2023-03-28 13:14 出处:网络
The \'London Style\' of TDD suggests focusing on object roles, responsibilities and collaborations, 开发者_JS百科using mock objects to drive out layers of large scale component design in a top down pr

The 'London Style' of TDD suggests focusing on object roles, responsibilities and collaborations, 开发者_JS百科using mock objects to drive out layers of large scale component design in a top down process (as opposed the 'Classic Style' which focuses on algorithmic refinement of methods).

I understand the basic approach, but am wondering how you reconcile this form of TDD (which still emphasises writing a test first) with the more natural way in which we design components, ie. sketching logical designs of related classes and defining their roles and responsibilities on paper / in our heads well before we start writing any code.

Appreciate some real-world advice.


I don't see a need to reconcile TDD (in any form) with "natural" component design. Testing implies that you have an idea of what you test, at the very least you have an interface to some level of precision. Starting out at a coarse-grained component definition seems very "natural" to me.


:)

'London Style' is basically good OOP combined with Outside-in (acceptance test) driven TDD (I am assuming you mean an approach similar to the GOOS book). That is the way that it "should" be done ; although the "classical" people should have been more explicit about it. I'm not sure there is such a classification among the practitioners (although there are people who are faster with TDD and people who struggle with it). State-based and interaction-based are styles and are not fits-all-sizes approaches. You need to choose the style for the task at hand.

The problem with doing "TDD in a corner" is that you may end up with well tested code that works but still does the wrong thing from the customers perspective.

Evolution has landed us now into an ATDD cycle which is TDD done at the customer/acceptance level which drives an inner TDD cycle for developers to make the acceptance test pass.

On the "reconcilation": I've found 'listening to the tests' quite enlightening once you have tuned your ears.. let the tests drive the design.
This is also aligned to the BDD folks. I recommend picking up the RSpec book which has a walkthrough in the first section of the book.

0

精彩评论

暂无评论...
验证码 换一张
取 消