K
K
Kirill Popolov2014-03-25 09:42:08
Software testing
Kirill Popolov, 2014-03-25 09:42:08

What is the need for TDD?

I am mastering the book Ruby on Rail Tutorial.
For every sneeze, there is at least one test. For example, checking for the presence of a certain phrase in the title. First I write a test, check that it fails, then insert the phrase into the title, then test again. What is the point?
What's worse than writing a piece of code and then testing it, or not testing at all if the required behavior is implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yuri Morozov, 2014-03-25
@ezhikov

The easiest way to look at it this way is that you write your own technical requirements with tests.
I want such and such functionality (I wrote a test), and so far this is not there (the test has failed).
If you do not check tests for preliminary failure, you would still have to write tests for tests, since there is a chance to write a test that will always pass.
Regarding the "behavior implemented": no one guarantees that in the course of subsequent development or (updating the framework) the behavior will not suddenly fall off, so even if it works now, it would be nice to keep an eye on it.

G
green_turtle, 2014-03-25
@green_turtle

TDD is a way of developing first and foremost. It's more about application architecture and design. When you write tests, you come up with the architecture of your application: a model, its relationships, etc. By looking at the tests, you should understand what and how your application does.
A rough example: you want to write an application that transfers money from one account to another. Having started writing, for example, the test "There must be an error with a negative balance of the first account", you still do not have any model (classes) at all. So you start thinking about how everything will work right in the test: I need an AccountService class to do transfers, an Account class that contains account information, and so on. Having written the logic, of course the test will be "red" because. you haven't written such classes yet, BUT now is the time to make the test green - write these classes and only the business logic that the test checks.

A
afiskon, 2014-03-25
@afiskon

There is a little about the essence of unit tests and TDD.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question