I can not understand how TDD has managed to gain such popularity. Why? Because I think this is the most irrational approach to development:
- You must write a test that fails.
A waste of time . You did not write a single line of code, but you wrote 20 lines of code to make sure that what you did not write does not work. - You should write a test that implements your thoughts on how this should work.
Waste of time. During the time you implemented your thoughts in test strings, you could realize your thoughts in lines of code . - You must write the code so that it passes the written test.
And at this time you could already be engaged in refactoring the written code. - Refactoring.
Another feature. As we know, web development involves developing what the end user will interact with through a browser. The TDD approach assumes maximum abstraction from the browser and uses only the command line to test the code. Smell that smell? It smells like logic.
So that my words do not sound unreasonable, I will give you an example of how I tried to master this branch.
Initially, I knew that people dislike the standard test framework in rails. And I also knew that the overwhelming majority preferred Rspec to him.
First of all, I, of course, decided to read the documentation for Rspec. By the first link in google I got to this page . Beautiful landing-page with a bunch of video discharge about anything. OK, I read the documentation , I decided. Absolutely nothing this page has brought me anything sensible. Only below was the link to some Relish. What it is and what side it refers to the Rspec is not clear. Okay, go on.
Only from there with the unremarkable Rspec-core link (guess 2) I got on something that somehow looks like what I'm looking for. Any code samples. Yes, immediately the code. It is not clear how to establish what structure the folders should have, how to name files, how to run - nothing.
A day later, having scoured a bunch of information about this, I learned where to put the files, how to name the folders, what to require, what methods to use (base). Helped me in this rather useful screencasts (on which, incidentally, the application was completely developed without using tests, and the tests were written “for teaching us purposes” when everything was obviously working as it should, and in this case the tests were customized and not vice versa (as TDD suggests), which once again proves the uselessness of using it. There was not any specific information (in the form of a guide, as was done in the case of rails, or at least a common start) neither on Habré, nor on the railscasts (even with a pro-subscription), in which R. Bates in his usual manner "rode "on the tops, having shown a typical example from the row" do this, I did this, goodbye to this. "
Sit down to write. Create an application, install the necessary gems, write. I decided to start in order. Routing. Wrote tests that were supposed to fail. It was not the tests that failed, but the Rspec itself. It turned out the syntax error (correctly, I still need to know how to write). We spend time searching for examples. We realize. Tests failed. We implement the code (and what should I implement there? I wrote the necessary paths for me). Tests passed. On everything about everything it took me about 3 hours. During this time, I would have managed to implement not only the routing logic, but also the logic of the model and, in part, some controllers.
I decided to start writing controllers. Again he rested in the banal ignorance and inability to use the new tool. As a person who has been taught by some kind of experience, he did not curse everyone and everything in this, but simply got into the documentation. Okay, google, "rspec controller". This is all that provides us, as far as I understand, official documentation . Again this Relish. At this stage, I matyuknulsya, sent everything to hell and decided to relax a bit. Now, after a break, I write here. And no, I’m writing not to speak out or once again, but to the public, to curse this TDD, but to figure it out.
Yes, even with all my failures, I want to figure out, first, why is this TDD so popular? Why does everyone “strongly recommend closing the browser and writing a couple of tests” when you can safely (and even more useful from the point of view of the psyche) get away with a simple visit to localhost:3000 ? What motivates all those who are so hard (if any, and not just window dressing) use TDD? And most importantly: what is the danger of abandoning this approach? Could a refusal have any impact on your resume or job search?
If there are really weighty arguments against my point of view, then I ask you to back up your answer with references to training materials on this topic (preferably from the inside, supported by real-life examples and covering at least half of what can be encountered in real use).
Thanks to those who mastered. I apologize in advance if it offended someone's feelings. It is assumed that all that is written above - IMHO.