"Write Code to fit a Test" -> "...">

Test & # 8594; Code & # 8594; Refactor, when should we start refactoring?

TDD Circle:

"Write failing Test" -> "Write Code to fit a Test" -> "Refactor"

The Coding step assumes that we should write the code as simple as possible, just to fix a failed test. We should not write complex code until it is really needed.

The next step is Refactor. Should we reorganize only the written code? I think it makes no real sense, since we should be content with the code as the tests pass.

Probably, refactoring activities should be forcedly connected with something, for example, when writing code, test failures occur. Here are some possible factors:

  • The next test to be written requires some changes in the system (refactoring)
  • Performance is bad. We need to improve it without breaking functionality
  • A review of the code shows that the written code is hard to understand.

What other reasons are you starting refactoring?

In addition, this scheme is correct:

"Write failing Test" -> "Code" -> "Refactor" -> "Write failing Test"

or maybe it should be considered as

"Write failing Test" -> "Code/Refactor" -> "Write failing Test"
+
"External factor (like bad performance)" -> "Refactor".
+5
source share
5 answers

TDD is a great tool to help you get the job done. A problem with:

"Write failing Test" → "Code / Refactor" → "Write failing Test"

you suggest if this is easy:

"Write failing Test" → "Refactor" → "Code" → "Write failing Test"

or then

"Write failing Test" → "Refactor" → "Refactor" → "Refactor" → "Code" → "Write failing Test"

. , . , . , , . , .

, , .

:

  • , , . " " , , , . , : , . , , . ?

  • , , TDD , . (. .) , , , , " ", . , "" . , , , , , , . TDD - , . , , , , , . .

+5

; , , . .

, , - , ?

+9

... "" TDD. XYZ TDD, , ( ..). , , . , , , , , .

, , , TDD, ( , ), , , .

+1

, , , , , , -. , , , . , , , , -, .

-, , , , , . . , , , red/green/refactor. , , , .

+1

, , ?

+1

All Articles