TDD: Why "Red Green Refactor" instead of "Green Refactor"?

I have been doing professional programming for 4 months. TDD is not negotiable in my GO-JEK company. Here is my observation: People tend to write code first and then write tests for it. This seems to be more convenient for people with 4-5 years of experience developing s / w and not after TDD before. So why do people write a failed test first and then write code to pass it on? Why don't people write code first and then add a test for it? We can refactor in any way.

+4
source share
3 answers

That's a good question. Since we ultimately want our tests to pass, why not write them to pass first.

The answer is that we really want our tests to stimulate development. We want the tests to be the first. Because when we write a test that needs some functionality, a concrete expression of what is needed and that the new bit of functionality is well defined. Initially, this functionality does not exist (therefore, the test is red); when we have successfully added functionality, the test is green. This is a pure definition: either functionality is present, or the test passes, or not, and the test does not work.

( ), , . - , - , , . , , , , - , .

+7

, , , unit test, . , - , , , .

"failing" , .

+1

- , , (TDD), (, ), RED - GREEN - .

, , , (, ), , , , . , , ( unit test )?

0

Source: https://habr.com/ru/post/1657924/


All Articles