How to handle TDD refactoring phase

During a TDD session, suppose I write a failed test and then pass it. I will reorganize by extracting code from the source block using refactoring such as Extract Class and Move Method. Now suppose my initial test no longer covers the extracted code, because the source code now breaks its dependencies, as is the case for Unit test.

Is it right to return and modify tests on the extracted code? Or did I make a mistake in how I ended up with unverified code during refactoring? It seems to me that since my code base is scalable and I have to refactor, I am updating a lot of tests for reorganized code. It is very uncomfortable. Am I reorganizing incorrectly?

+5
source share
2 answers

Now suppose my initial test no longer covers the extracted code, because the source code now disables its dependencies, as is the case for Unit test.

Often arising dependencies depend on what needs to be done, but not always, and I would not say that it is "right for the unit test" to make fun of all the dependencies.

In the TDD refactoring phase, you must make a difference in the production code, which does not affect the passing of the tests. And you should not change tests at the same time.

You may want to modify your tests later so that the extracted code is tested independently of the source code and mocked the source tests.

+5
source

, - . , , , .

, , -, , , . .

0

All Articles