

Both are extremes. It all depends on the situation. In general, tests are a very sick and holivar topic. The question is not yet closed about which tests to write at all or not: units, functional, or integration (or all).Let us give an example of a possible dialogue between the manager and the architect.
A: - Do we want 100% coverage?It is widely believed that the design of average quality will provide coverage for key pieces of code by 80-85%, and every subsequent 5% will take more and more resources (labor and time).
M: - Yes, of course.
A: - Great, only this will delay the development by half and complicate the test code maintenance by an order of magnitude.
Moreover, TDD author Kent Beck once expressed the idea that unnecessary tests can be deleted. He calls such tests delta coverage, an additional coverage provided by a specific test suite. If this additional coverage is 0, then the test can be safely removed.
Martin Fowler led two simple rules of thumb that define the lower and upper limits of coverage: if you are not sure about your changes, and many of them lead to failures, but do not break tests, then there are too few tests. If too many tests break down with every change, then there may be too many tests.
The Single Responsibility PrincipleUltimately, this will give the entire system greater mobility and flexibility.
The Open Closed Principle
The Liskov Substitution Principle
The Interface Segregation Principle
The principle of inversion of dependence (The Dependency Inversion Principle)
You can write code without TDD, if you are sure that it will not come to the dotted line. For example, you write a small project to automate the internal work, or create a business card site.It should be understood that TDD is not a guarantee of the quality of your code, but with it it is easier to keep the system in tune, he concludes.
David Hansson warns that enthusiasm for testing and trying to test everything in complete isolation (when we test only the current class, without its dependencies or auxiliary low-level classes) leads to a jumble of unnecessary layers of abstraction and over-sophisticated design.When the system begins to grow, the problem is not in the number of levels of abstraction, but in the number of isolation levels. That is, the very fact that class A calls a class B method, which refers to class C, does not represent a problem until an isolation level appears in the form of an interface between each of these classes.On the other hand, some Habra users are looking at this topic.
It should be understood that the use of such methodologies as TDD implies that developers, not testers, write autotests. These are programming and coding methodologies, and not the development of a finished product, which involves a lot of people from PM and technical writers to admins and technical support. Developers often refer to the introduction of TDD-like as putting the testers duties on them.Feedback from user Tagakov :
TDD is really not what testers should do. Their task is to write functional tests and, if they have enough qualifications, integration. TDD is not TDD, but developers from time immemorial have been testing, running their code and testing how it works, unit testing is more a formalization of this process.Feedback from user Kunis :
If the test is written before and provided to the programmer as source data, it becomes a “technical requirement” (requirement). Of course, the one who writes the test must write and program all the required mocks in advance. Haha, I would not want to be the programmer whose responsibility it is to program tests for others.
Well, can a programmer himself write tests to his code in advance? In my experience, no and no. Programmers (and I and the vast majority with whom I discussed it) just think in the opposite direction. Yes, at first people tried to honestly follow the methodology. But after some time, they started to write the code first and then add tests to it. And after some time, the tests lost their versatility and meticulousness. And then “shtob was” was written at all, since they ask.
Does it even need it?
I do not use TDD in its classic sense. In general, it is unlikely that someone from professionals considers encyclopedic articles as a guide to action. We “suffered” our approach as part of a successful project, so we have real experience, not “stupid use of other people's ideas.”
Rather, we use synthesis from TDD and our own ideas about how to develop software. Even if these “external ideas” come from very smart people, they should be critically interpreted and adapted to the real company, the existing team and the strategy of development and quality assurance.
In our opinion, it is rather difficult to strictly separate these approaches and not at all necessary. It so happened that in our team we usually combine the use of both approaches in one project, and even sometimes when developing one block of code.
Well, for example, when we write part of a project to work with services through an API, we write first the tests and only then the code (TDD). However, after the implementation, it often happens that the tests written in advance are not enough and you have to add them, achieving 100% coverage (TLD).
Sometimes, even on very simple controllers (a normal resource with basic CRUD), first simple tests are written, and then a code (TDD). This gives us confidence that nothing is forgotten in the original implementation. In the future, with the development of the project, in most cases, the tests are written after writing the code (TLD).
Often there are tasks to implement the algorithm for known input / output data, here too the TDD approach is mainly used. If there are ready input and output data, then it is very easy to write a simple test using them, and only then implement this algorithm, being sure of the result.
Most often, the TLD approach is applied during refactoring. First, we test the existing implementation with tests and then rewrite it.
If we talk about the ratio of the use of TDD and TLD in projects, the TLD usually benefits. Developers who simply write tests are always more than those who are able to "think tests" and write tests in advance.
Source: https://habr.com/ru/post/313584/
All Articles