You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapter_philosophy_and_refactoring.asciidoc
+19-17Lines changed: 19 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -786,8 +786,7 @@ It's time for a little recap, and perhaps even some flowcharts.
786
786
Forgive me, years misspent as a management consultant have ruined me.
787
787
On the plus side, it will feature recursion.
788
788
789
-
What is the overall TDD process?
790
-
789
+
What is the overall TDD process?
791
790
Well, one very common way to present it is using the three words
792
791
_Red, Green, Refactor_. See <<red-green-refactor>>..
793
792
@@ -798,37 +797,40 @@ image::images/red-green-refactor-excalidraw.png["Red, Green and Refactor as thre
798
797
What if we want to drill down in a bit more detail? Here's what
799
798
we've been doing, including what I call the _unit test/code cycle_:
800
799
801
-
We write a test. We run the test and see it fail.
802
-
We write some minimal code to get it a little further.
803
-
We rerun the test and repeat until it passes.
804
-
Then, we look for opportunities to refactor our code,
805
-
using our tests to make sure we don't break anything. See <<simple-tdd-diagram>>.
800
+
* We write a test.
801
+
* We run the test and see it fail.
802
+
* We write some minimal code to get it a little further.
803
+
* We rerun the test and repeat until it passes (the unit test / code cycle)
804
+
* Then, we look for opportunities to refactor our code,
805
+
using our tests to make sure we don't break anything.
806
+
807
+
See <<simple-tdd-diagram>>.
808
+
806
809
807
810
[[simple-tdd-diagram]]
808
-
.Overall TDD process
811
+
.Overall TDD process including the unit test / code cycle
809
812
image::images/tdd-process-unit-tests-only-excalidraw.png["A flowchart with boxes for tests, coding and refactoring, with yes/no labels showing when we move forwards or backwards"]
810
813
811
814
But how does this apply when we have functional tests _and_ unit tests?
812
-
Well, you can think of the functional test as being a high-level view of the cycle,
815
+
Well, you can think of the functional test as driving a higher-level version of the same cycle,
813
816
where "writing the code" to get the functional tests to pass
814
-
actually involves using another, smaller TDD cycle which uses unit tests.
817
+
actually involves using another, smaller TDD cycle driven by unit tests.
815
818
See <<double-loop-tdd-diagram>>.
816
819
817
-
We write a functional test and see it fail.
818
-
Then, the process of "writing code" to get it to pass is a mini-TDD cycle of its own:
819
-
we write one or more unit tests, and go into the unit-test/code cycle until the unit tests pass.
820
-
Then, we go back to our FT to check that it gets a little further,
820
+
* WWe write a functional test and see it fail.
821
+
* Then, the process of "writing code" to get it to pass is a mini-TDD cycle of its own:
822
+
* we write one or more unit tests, and go into the unit-test/code cycle until the unit tests pass.
823
+
* Then, we go back to our FT to check that it gets a little further,
821
824
and we can write a bit more of our application--using more unit tests, and so on.
822
825
823
-
TODO - a little more nuance here
826
+
TODO - next paragraph needs work. clarification.
824
827
825
828
What about refactoring, in the context of functional tests?
826
829
Well, that means we use the functional test to check that we've preserved the behaviour of
827
830
our application, but we can change or add and remove unit tests, and use
828
831
a unit test cycle to actually change the implementation.
829
832
830
-
The functional tests are the ultimate judge of whether your application works
831
-
or not. The unit tests are a tool to help you along the way.
833
+
The functional tests are the final sanity-check that your application works. The unit tests are there to help you figure out all the lower level bits you need along the way.
832
834
833
835
This way of looking at things is sometimes called "Double-Loop TDD". One of my
834
836
eminent tech reviewers, Emily Bache, wrote http://bit.ly/1iXzoLR[a blog post]
0 commit comments