Should I use TDD when starting a new project?
I am working on a new PHP project, and while I like TTD, I find it more difficult than helpful at this stage of the project.
I started writing unit tests, but now as I get deeper into prototyping some of the application's features, I find myself rewriting bits and pieces of the main structure along with writing the tests. I feel like I'm spending a lot more time rewriting tests, where maybe I should wait until I'm more alpha-beta phase of the project.
Should I be writing a unit test from the start, even though there is a good chance I will have to rewrite them?
source to share
Yes, this is the best way to understand your system and build a solid API.
It looks like you need to move your tests to a higher level. Do not test individual methods, test units of functionality. The more recent buzzword is BDD or Context / Specification , but that's not quite the case as I haven't met a tdd practitioner yet who hasn't at least tried to move in that direction.
source to share
Of course you are going to rewrite them, everything will change.
If you do a complete and thorough analysis of the requirements, things will change (most likely when you did this chimera) and you will have to re-analyze.
But if you dive right in and get the code written, and some of the results are sorted, you don't have any useful analysis, no tests, and then the entire sales department rubs their hands because shipped = sold.
Iteration, write tests you can run, run them, see where you go. TDD or classic water drop, there's a lot of work ahead of you before you have a little software.
Do the front job second, not very rewarding and never happened.
Maybe you need a little more proof of concept, or a plot boarding house, or a deity forbidding analysis, but all diving into it makes fake smilies on the dashboard, and the only credit you get for that is hitting backgammon when the wheels are off. , and a technical debt crisis not related to conventional style.
source to share
I find it seems to be more of a hindrance than of being helpful at this stage of the project.
Why? Can you define your problems more objectively?
now as I get deeper into prototyping some function applications, I find myself rewriting bits and pieces of the kernel along with writing tests. I feel like I spend a lot more time rewriting tests, where maybe I should wait until I become more alpha-beta phase of the project.
- Don't use TDD when prototyping. Prototypes need to acquire knowledge ... preferably ... preferably in a time box. Once you eliminate the uncertainty, you throw away the prototype. Start again this time with TDD.
- Are your tests changing because you now have a better understanding? Or is it so that the tests are matched with the implementation (knows how the tested object is implemented versus the services offered)? The first is inevitable if you don't have exemplary foresight ... changing requirements, changing tests. The latter is the smell .. and can be avoided by focusing on what instead of How?
- The problem with expecting your product / application to stabilize is that you might end up putting it off forever OR you might end up in a design that's hard to test. This will make the written tests (later) more difficult than necessary. TDD is easier if you work in small increments on the code base under test. Tests also provide a safety net to help you make changes with confidence and provide instant feedback.
source to share
Yes, I find it very important to start writing tests from the beginning. TDD (Test Driven Development) is not just about testing individual classes on your own. It should be guided by the decisions you make during the design phase.
When you write tests first, you will have a better understanding of your problem. You say that you will probably rewrite them later. If so, it probably means that you will have a better understanding of your system, which is good. You can then redesign your system by performing further tests or rephrasing existing ones.
This may seem like a waste of time, but it is not how you better understand the system you are working on.
One of the books I'm currently reading (Growing Object Oriented Test Driven Software) mentions the concept of a "Walking Skeleton". This suggests that you should use TDD to develop a minimal working solution, even if it is very simple.
Another important point is to try to automate your deployment from the beginning. This is not exactly a unit test, but it is a deployment test that is equally, if not more important, than unit tests. If you do this kind of testing early on in a project, you won't run into unexpected issues near the release date. You will also get a better understanding of how the different components of your system fit together.