I'm starting a new project and I want to use Test Driven Development, but I having trouble understanding how to write tests when you don't have a data model or interfaces.
IMO, the data model and interfaces should be written. Then a couple of features should be implemented to verify the data model and interfaces have "matured." (aka changes to either will be minimal). Then I would write the unit tests. After that step, I think you can follow TDD.
Is this the correct approach?
On a side note, does it seem l开发者_高级运维ike some of these new techniques like TDD don't account or document what to do for new projects.
Like they say, "start with a failing unit test".
- You don't need a data model until and unless it's needed in order to fix a failing unit test.
- You don't need interfaces until they're necessary (to fix a failing unit test)
Maybe if you give an example of an application, we can help you find the first few failing tests.
TDD does NOT constitute a multi-day process of writing tests then writing code to make those tests pass. TDD is about incorporating test effort in a parallel manner with the development effort.
Writing a few tests to address a potential class then writing the class would be an example of a parallel effort. Writing tests to address a module composed of a multitude of classes then writing the classes to make these tests pass is not a parallel effort and should be avoided since refactoring is inevitable throughout development.
You get a general idea of the classes you need then you write a test, watch it fail, make it pass, and repeat. you might realize you need to move methods around or create new classes but thats part of the process.
See this video for a live demo http://katas.softwarecraftsmanship.org/?p=80
The whole point is that when you write a test, it's going to fail. You don't need data models or interfaces to write a failing test.
http://jamesshore.com/Blog/Red-Green-Refactor.html
精彩评论