Skip to content

Commit 3c9c64c

Browse files
committed
update explanation for refactoring against failing tests
1 parent 913a273 commit 3c9c64c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

chapter_12_organising_test_files.asciidoc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -884,13 +884,15 @@ Don't forget the "Refactor" in "Red, Green, Refactor"::
884884
((("Red/Green/Refactor")))
885885
886886
Don't refactor against failing tests::
887-
* In general: refactoring against failing tests can easily introduce new
888-
issues and make it a lot more difficult to spot them.
889-
* Refactoring against failing FTs, however, is often necessary and excusable
890-
because FTs address user stories, focusing on the "what" in development.
891-
They cover extensive parts of the application, and aren't tightly tied to
892-
the code. Unlike unit tests, which focus on the "how" to implement the
893-
functionality, guiding the implementation more directly.
887+
* The general rule is that you shouldn't mix refactoring and behaviour
888+
change. Having green tests is our best guarantee that we aren't changing
889+
behaviour. If you start refactoring against failing tests, it becomes much
890+
harder to spot when you're accidentally introducing a regression.
891+
* This applies strongly to unit tests. With functional tests, because we
892+
often develop against red FTs anyway, it's sometimes more tempting to
893+
refactor against failing tests. My suggestion is to avoid that temptation
894+
and use an early return, so that it's 100% clear if, during a refactory,
895+
you accidentally introduce a regression that's picked up in your FTs.
894896
* You can occasionally put a skip on a test which is testing something you
895897
haven't written yet.
896898
* More commonly, make a note of the refactor you want to do, finish what

0 commit comments

Comments
 (0)