SlideShare a Scribd company logo
1 of 126
Download to read offline
Real Developers Don’t Need Unit Tests
Mythbusting TDD myths




                        John Ferguson Smart
                        Wakaleo Consulting Ltd.
                        http://www.wakaleo.com
                        Email: john.smart@wakaleo.com
                        Twitter: wakaleo
Introduction
Real Developers Don’t Need Unit Tests
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?




             Chuck Norris’s code doesn’t have bugs
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?




               Chuck Norris’s code doesn’t have bugs




         His code always work. ALWAYS.
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?




                     Chuck Norris’s code is perfectly
                      designed the first time round
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?




                      Chuck Norris’s code is perfectly
                       designed the first time round




         His favorite design pattern is the
                Roundhouse Kick
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?


                    Chuck Norris doesn’t need
                     technical documentation
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?


                      Chuck Norris doesn’t need
                       technical documentation




          He just stares down the code until it
         tells him everything he wants to know
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
      Executable requirements?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
      Executable requirements?


                       Chuck Norris doesn’t need
                     requirements to be executable
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
      Executable requirements?


                       Chuck Norris doesn’t need
                     requirements to be executable




        He can execute whatever he wants
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
      Executable requirements?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
      Executable requirements?
           Acceptance Tests?
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
      Executable requirements?
           Acceptance Tests?


                      Chuck Norris doesn’t need
                          acceptance tests
Introduction
Real Developers Don’t Need Unit Tests
    Bugs?
  Emergent design?
   Technical documentation?
      Executable requirements?
           Acceptance Tests?


                        Chuck Norris doesn’t need
                            acceptance tests




        No one refuses to accept Chuck
Introduction
Real Developers Don’t Need Unit Tests
Introduction
Real Developers Don’t Need Unit Tests




           OK, so Chuck Norris doesn’t need Unit Tests
Introduction
Real Developers Don’t Need Unit Tests




           OK, so Chuck Norris doesn’t need Unit Tests




            But what about the rest of us?
TDD Basics
TDD Basics




         So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests




              So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests
TDD is a design strategy:




              So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests
TDD is a design strategy:
 Write better-designed code




               So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests
TDD is a design strategy:
 Write better-designed code
 Have more confidence in our code




               So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests
TDD is a design strategy:
 Write better-designed code
 Have more confidence in our code
 Make changes more easily




               So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests
TDD is a design strategy:
 Write better-designed code
 Have more confidence in our code
 Make changes more easily
 Write code that meets user requirements more accurately




               So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests
TDD is a design strategy:
 Write better-designed code
 Have more confidence in our code
 Make changes more easily
 Write code that meets user requirements more accurately
 (and incidentally...)




                  So what is this TDD thing, anyway?
TDD Basics
TDD is not about writing tests
TDD is a design strategy:
 Write better-designed code
 Have more confidence in our code
 Make changes more easily
 Write code that meets user requirements more accurately
 (and incidentally...)
 Build up a comprehensive set of automated tests



                  So what is this TDD thing, anyway?
TDD Basics
The TDD development process
“Never write a single line of code unless you have a failing automated test.
                           Eliminate duplication.”
                                                                       - Kent Beck
TDD Basics
The TDD development process
“Never write a single line of code unless you have a failing automated test.
                           Eliminate duplication.”
                                                                           - Kent Beck




     TEST                          Write a failing unit test. Ensure that it fails.
TDD Basics
The TDD development process
“Never write a single line of code unless you have a failing automated test.
                           Eliminate duplication.”
                                                                           - Kent Beck




     TEST                          Write a failing unit test. Ensure that it fails.



                   CODE                 Write production code to make the test pass.
TDD Basics
The TDD development process
“Never write a single line of code unless you have a failing automated test.
                           Eliminate duplication.”
                                                                           - Kent Beck




     TEST                          Write a failing unit test. Ensure that it fails.



                   CODE                 Write production code to make the test pass.



                               REFACTOR                           Tidy up the design
TDD Basics
               TEST


              CODE


             REFACTOR
TDD Basics
Step 1) Write a test     TEST


                        CODE


                       REFACTOR
TDD Basics
Step 1) Write a test                      TEST

 Design your code from the outside-in
                                         CODE


                                        REFACTOR
TDD Basics
Step 1) Write a test                      TEST

 Design your code from the outside-in
  How will your code be used?            CODE


                                        REFACTOR
TDD Basics
Step 1) Write a test                         TEST

 Design your code from the outside-in
  How will your code be used?               CODE

  Design a clean interface for your code
                                           REFACTOR
TDD Basics
Step 1) Write a test                                 TEST

 Design your code from the outside-in
  How will your code be used?                       CODE

  Design a clean interface for your code
  Implement only features that are really needed   REFACTOR
TDD Basics
Step 1) Write a test                                 TEST

 Design your code from the outside-in
  How will your code be used?                       CODE

  Design a clean interface for your code
  Implement only features that are really needed   REFACTOR

  Provide examples of how you expect your code
  to be used
TDD Basics
Step 1) Write a test                                      TEST

 Design your code from the outside-in
  How will your code be used?                            CODE

  Design a clean interface for your code
  Implement only features that are really needed        REFACTOR

  Provide examples of how you expect your code
  to be used
                      How will my code be used by the
                          rest of the application?




                                 ?
TDD Basics
               TEST


              CODE


             REFACTOR
TDD Basics
Step 2) Write some code     TEST


                           CODE


                          REFACTOR
TDD Basics
Step 2) Write some code                      TEST

 Just enough code to make the tests pass
                                            CODE


                                           REFACTOR
TDD Basics
Step 2) Write some code                                 TEST

 Just enough code to make the tests pass
 Might mean a non-optimal solution at this stage...    CODE


                                                      REFACTOR
TDD Basics
Step 2) Write some code                                  TEST

 Just enough code to make the tests pass
 Might mean a non-optimal solution at this stage...     CODE


                                                       REFACTOR




                       Just make it pass the test...
TDD Basics
               TEST


              CODE


             REFACTOR
TDD Basics
                                                     TEST


                                                    CODE


                                                   REFACTOR




             It works. Now let’s tidy things up.
TDD Basics
Step 3) Tidy up                                           TEST


                                                         CODE


                                                        REFACTOR




                  It works. Now let’s tidy things up.
TDD Basics
Step 3) Tidy up                                             TEST

 Evolutionary (emerging) design
                                                           CODE


                                                          REFACTOR




                    It works. Now let’s tidy things up.
TDD Basics
Step 3) Tidy up                                              TEST

 Evolutionary (emerging) design
  Keep the code clean!                                      CODE


                                                           REFACTOR




                     It works. Now let’s tidy things up.
TDD Basics
Step 3) Tidy up                                              TEST

 Evolutionary (emerging) design
  Keep the code clean!                                      CODE

  Remove duplication and fix design problems
                                                           REFACTOR




                     It works. Now let’s tidy things up.
TDD Basics
Step 3) Tidy up                                                TEST

 Evolutionary (emerging) design
  Keep the code clean!                                        CODE

  Remove duplication and fix design problems
  Restructure existing code - no new features!               REFACTOR




                       It works. Now let’s tidy things up.
TDD Basics
Step 3) Tidy up                                                 TEST

 Evolutionary (emerging) design
  Keep the code clean!                                         CODE

  Remove duplication and fix design problems
  Restructure existing code - no new features!                REFACTOR

  Make sure the tests still pass!


                        It works. Now let’s tidy things up.
TDD in Action - the Game Of Life
TDD in Action - the Game Of Life


         So where do we start?
TDD in Action - the Game Of Life


         So where do we start?


             Let’s list some requirements
TDD in Action - the Game Of Life


                 So where do we start?


                     Let’s list some requirements



              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live cells with 2 or 3 live neighbours remain alive
- Dead cells with 3 neighbours become alive
TDD in Action




              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live User Story 1or Less than 2 neighbours die
       cells with 2 - 3 live neighbours remain alive
- Dead cells cell with less than 2 live neighbours
   Given a with 3 neighbours become alive
   When the next generation is created
   Then this cell will die
TDD in Action


                     Now what?




              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live User Story 1or Less than 2 neighbours die
       cells with 2 - 3 live neighbours remain alive
- Dead cells cell with less than 2 live neighbours
   Given a with 3 neighbours become alive
   When the next generation is created
   Then this cell will die
TDD in Action


                     Now what?


                       So what do we mean by this first requirement?



              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live User Story 1or Less than 2 neighbours die
       cells with 2 - 3 live neighbours remain alive
- Dead cells cell with less than 2 live neighbours
   Given a with 3 neighbours become alive
   When the next generation is created
   Then this cell will die
TDD in Action




              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live User Story 1or Less than 2 neighbours die
       cells with 2 - 3 live neighbours remain alive
- Dead cells cell with less than 2 live neighbours
   Given a with 3 neighbours become alive
   When the next generation is created
   Then this cell will die
TDD in Action


                  So what do we have to code for this one.




              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live User Story 1or Less than 2 neighbours die
       cells with 2 - 3 live neighbours remain alive
- Dead cells cell with less than 2 live neighbours
   Given a with 3 neighbours become alive
   When the next generation is created
   Then this cell will die
TDD in Action


                  So what do we have to code for this one.


                   Dunno yet. Let’s write some acceptance tests to find out



              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live User Story 1or Less than 2 neighbours die
       cells with 2 - 3 live neighbours remain alive
- Dead cells cell with less than 2 live neighbours
   Given a with 3 neighbours become alive
   When the next generation is created
   Then this cell will die
TDD in Action


                  So what do we have to code for this one.


                    Dunno yet. Let’s write some acceptance tests to find out



              The Game of Life
- Live cells with less than 2 live neighbours die
- Live cells with more than 3 live neighbours die
- Live UserUser StoryLessAcceptance criteria die
       cells Story 1or 3 live neighbours remain alive
             with 2 - 1 - than 2 neighbours
- Dead cells cell with less than 2 live neighbours
   Given a with 3 neighbours become alive
   Sample grid transitions:
   1)                   2)
   When the next generation is created
   Then this cell will die
TDD in Action
TDD in Action


        Great, so now I can start coding, right?
TDD in Action


        Great, so now I can start coding, right?

               Not so fast, hot shot. We need to turn this into an
                            ‘executable requirement’
TDD in Action


        Great, so now I can start coding, right?

                 Not so fast, hot shot. We need to turn this into an
                              ‘executable requirement’


        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
            }
        }
TDD in Action




        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
            }
        }
TDD in Action


            I still don’t know what to write in this test...




        public class GameOfLifeTest {

             @Test
             public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
             }
        }
TDD in Action


            I still don’t know what to write in this test...


                  Start by expressing what you are trying to achieve



        public class GameOfLifeTest {

             @Test
             public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
             }
        }
TDD in Action


            I still don’t know what to write in this test...


                  Start by expressing what you are trying to achieve



        public class GameOfLifeTest {

             @Test
             public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                 String initialGrid = "...n" +
                                      "...n" +
                                      "...";

                 String expectedNextGrid = "...n" +
                                           "...n" +
                                           "...";

                 String nextGrid = null;
                 assertThat(nextGrid, is(expectedNextGrid));
             }
        }
TDD in Action




        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                String nextGrid = null;
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


        But that test will fail! What now?




        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                String nextGrid = null;
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


        But that test will fail! What now?


            How you would like the code to look, if you had to use it?



        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                String nextGrid = null;
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


        But that test will fail! What now?


            How you would like the code to look, if you had to use it?



        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                Universe theUniverse = new Universe(seededWith(initialGrid));
                theUniverse.createNextGeneration();

                String nextGrid = theUniverse.getGrid();
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


     public class GameOfLifeTest {

         @Test
         public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
             String initialGrid = "...n" +
                                  "...n" +
                                  "...";

             String expectedNextGrid = "...n" +
                                       "...n" +
                                       "...";

             Universe theUniverse = new Universe(seededWith(initialGrid));
             theUniverse.createNextGeneration();

             String nextGrid = theUniverse.getGrid();
             assertThat(nextGrid, is(expectedNextGrid));
         }
     }
TDD in Action
         So what’s so special about this test?


     public class GameOfLifeTest {

         @Test
         public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
             String initialGrid = "...n" +
                                  "...n" +
                                  "...";

             String expectedNextGrid = "...n" +
                                       "...n" +
                                       "...";

             Universe theUniverse = new Universe(seededWith(initialGrid));
             theUniverse.createNextGeneration();

             String nextGrid = theUniverse.getGrid();
             assertThat(nextGrid, is(expectedNextGrid));
         }
     }
TDD in Action
         So what’s so special about this test?
                                                   The test name describes
                                                   the expected behaviour
     public class GameOfLifeTest {

         @Test
         public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
             String initialGrid = "...n" +
                                  "...n" +
                                  "...";

             String expectedNextGrid = "...n" +
                                       "...n" +
                                       "...";

             Universe theUniverse = new Universe(seededWith(initialGrid));
             theUniverse.createNextGeneration();

             String nextGrid = theUniverse.getGrid();
             assertThat(nextGrid, is(expectedNextGrid));
         }
     }
TDD in Action
         So what’s so special about this test?
                                                   The test name describes
                                                   the expected behaviour
     public class GameOfLifeTest {

         @Test
         public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
             String initialGrid = "...n" +
                                  "...n" +
                                  "...";

             String expectedNextGrid = "...n" +
                                       "...n" +
                                       "...";

             Universe theUniverse = new Universe(seededWith(initialGrid));
             theUniverse.createNextGeneration();

             String nextGrid = theUniverse.getGrid();
             assertThat(nextGrid, is(expectedNextGrid));
         }
     }                We started by expressing our expectations
TDD in Action
         So what’s so special about this test?
                                                   The test name describes
                                                   the expected behaviour
     public class GameOfLifeTest {

         @Test
         public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
             String initialGrid = "...n" +
                                  "...n" +
                                  "...";

             String expectedNextGrid = "...n" +    The code is written for API
                                       "...n" +
                                                    users, not API developers
                                       "...";

             Universe theUniverse = new Universe(seededWith(initialGrid));
             theUniverse.createNextGeneration();

             String nextGrid = theUniverse.getGrid();
             assertThat(nextGrid, is(expectedNextGrid));
         }
     }                We started by expressing our expectations
TDD in Action
                   So what’s so special about this test?
                                                             The test name describes
                                                             the expected behaviour
              public class GameOfLifeTest {

                   @Test
                   public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                       String initialGrid = "...n" +
                                            "...n" +
                                            "...";

  It’s a working       String expectedNextGrid = "...n" +    The code is written for API
example of how                                   "...n" +
                                                              users, not API developers
to use the class                                 "...";

                       Universe theUniverse = new Universe(seededWith(initialGrid));
                       theUniverse.createNextGeneration();

                       String nextGrid = theUniverse.getGrid();
                       assertThat(nextGrid, is(expectedNextGrid));
                   }
              }                 We started by expressing our expectations
TDD in Action




        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                Universe theUniverse = new Universe(seededWith(initialGrid));
                theUniverse.createNextGeneration();

                String nextGrid = theUniverse.getGrid();
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


                  So what now?




        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                Universe theUniverse = new Universe(seededWith(initialGrid));
                theUniverse.createNextGeneration();

                String nextGrid = theUniverse.getGrid();
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


                  So what now?


                  This is our acceptance test. Now we drill down.



        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                Universe theUniverse = new Universe(seededWith(initialGrid));
                theUniverse.createNextGeneration();

                String nextGrid = theUniverse.getGrid();
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


                  So what now?


                  This is our acceptance test. Now we drill down.



        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                Universe theUniverse = new Universe(seededWith(initialGrid));
                theUniverse.createNextGeneration();

                String nextGrid = theUniverse.getGrid();
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action




        public class GameOfLifeTest {

            @Test
            public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                String initialGrid = "...n" +
                                     "...n" +
                                     "...";

                String expectedNextGrid = "...n" +
                                          "...n" +
                                          "...";

                Universe theUniverse = new Universe(seededWith(initialGrid));
                theUniverse.createNextGeneration();

                String nextGrid = theUniverse.getGrid();
                assertThat(nextGrid, is(expectedNextGrid));
            }
        }
TDD in Action


            So I guess you’ll say we need to write a test?




        public class GameOfLifeTest {

              @Test
              public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                  String initialGrid = "...n" +
                                       "...n" +
                                       "...";

                  String expectedNextGrid = "...n" +
                                            "...n" +
                                            "...";

                  Universe theUniverse = new Universe(seededWith(initialGrid));
                  theUniverse.createNextGeneration();

                  String nextGrid = theUniverse.getGrid();
                  assertThat(nextGrid, is(expectedNextGrid));
              }
        }
TDD in Action


            So I guess you’ll say we need to write a test?


                  Spot on! You catch on fast!



        public class GameOfLifeTest {

              @Test
              public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                  String initialGrid = "...n" +
                                       "...n" +
                                       "...";

                  String expectedNextGrid = "...n" +
                                            "...n" +
                                            "...";

                  Universe theUniverse = new Universe(seededWith(initialGrid));
                  theUniverse.createNextGeneration();

                  String nextGrid = theUniverse.getGrid();
                  assertThat(nextGrid, is(expectedNextGrid));
              }
        }
TDD in Action


            So I guess you’ll say we need to write a test?


                   Spot on! You catch on fast!

                  public class UniverseTest {

                   @Test
        public class GameOfLifeTest {
                   public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {

              @Test
                          String seededGrid = "...n" +
              public void aCellWithNoNeighboursShouldDieInTheNextGeneration() {
                                              "...n" +
                   String initialGrid = "...n" +
                                              "...";
                                        "...n" +
                                        "...";
                          Universe theUniverse = new Universe(seededWith(seededGrid));
                          String currentGrid = theUniverse.getGrid();
                   String expectedNextGrid = "...n" +
                          assertThat(currentGrid, is(seededGrid));
                                             "...n" +
                      }
                                             "...";
                 }

                   Universe theUniverse = new Universe(seededWith(initialGrid));
                   theUniverse.createNextGeneration();

                   String nextGrid = theUniverse.getGrid();
                   assertThat(nextGrid, is(expectedNextGrid));
              }
        }
TDD in Action




        public class UniverseTest {

            @Test
            public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {

                String seededGrid = "...n" +
                                    "...n" +
                                    "...";

                Universe theUniverse = new Universe(seededWith(seededGrid));
                String currentGrid = theUniverse.getGrid();
                assertThat(currentGrid, is(seededGrid));
            }
        }
TDD in Action


            So now can we code?




        public class UniverseTest {

             @Test
             public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {

                 String seededGrid = "...n" +
                                     "...n" +
                                     "...";

                 Universe theUniverse = new Universe(seededWith(seededGrid));
                 String currentGrid = theUniverse.getGrid();
                 assertThat(currentGrid, is(seededGrid));
             }
        }
TDD in Action


            So now can we code?


                   Yes, but just a little bit

        public class UniverseTest {

             @Test
             public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {

                 String seededGrid = "...n" +
                                     "...n" +
                                     "...";

                 Universe theUniverse = new Universe(seededWith(seededGrid));
                 String currentGrid = theUniverse.getGrid();
                 assertThat(currentGrid, is(seededGrid));
             }
        }
TDD in Action


            So now can we code?


                   Yes, but just a little bit

        public class UniverseTest {

             @Test              public class Universe {
             public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {
                                	    public Universe(String initialGridContents) {}
                 String seededGrid = "...n" +
                                	    public static String seededWith(String gridContents) {
                                     "...n" +
                                	        return null;
                                     "...";
                                	    }
                 Universe theUniverse = new Universe(seededWith(seededGrid));
                                    public void createNextGeneration() {}
                 String currentGrid = theUniverse.getGrid();
                 assertThat(currentGrid, is(seededGrid));
             }                      public String getGrid() {
        }                                return "...n" +
                                                "...n" +
                                                "...";
                                    }
                                }
TDD in Action
TDD in Action


       Er, isn’t that a bit too simple.
TDD in Action


       Er, isn’t that a bit too simple.

            Yes. We need another test to tease out
                  a more complete design
TDD in Action


       Er, isn’t that a bit too simple.

            Yes. We need another test to tease out
                  a more complete design


        public class UniverseTest {

            @Test
            public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {...}

            @Test
            public void aUniverseSeededWithANonEmpyGridContentWillContainThatGrid() {

                String seededGrid = "...n" +
                                    ".*.n" +
                                    "...";

                Universe theUniverse = new Universe(seededWith(seededGrid));
                String currentGrid = theUniverse.getGrid();
                assertThat(currentGrid, is(seededGrid));
            }
        }
TDD in Action


       Er, isn’t that a bit too simple.

            Yes. We need another test to tease out
                  a more complete design


        public class UniverseTest {

            @Test
            public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {...}

            @Test
            public void aUniverseSeededWithANonEmpyGridContentWillContainThatGrid() {

                String seededGrid = "...n" +
                                    ".*.n" +
                                    "...";

                Universe theUniverse = new Universe(seededWith(seededGrid));
                String currentGrid = theUniverse.getGrid();
                assertThat(currentGrid, is(seededGrid));
            }
        }
TDD in Action


       Er, isn’t that a bit too simple.

            Yes. We need another test to tease out
                  a more complete design

                                      public class Universe {

        public class UniverseTest {       private String currentContent;

            @Test                   	   public Universe(String initialGridContents) {
            public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {...}
                                    	       currentContent = initialGridContents;
                                    	   }
            @Test
            public void aUniverseSeededWithANonEmpyGridContentWillContainThatGrid() {
                                    	   public static String seededWith(String gridContents) {
                                    	   	    return gridContents;
                String seededGrid = "...n" +
                                    	   }
                                    ".*.n" +
                                    "...";
                                        public void createNextGeneration() {
                                        }
                Universe theUniverse = new Universe(seededWith(seededGrid));
                String currentGrid = theUniverse.getGrid();
                                        public String getGrid() {
                assertThat(currentGrid, is(seededGrid));
                                            return currentContent;
            }                           }
        }                           }
TDD in Action




         public class Universe {

             private String currentContent;

         	   public Universe(String initialGridContents) {
         	       currentContent = initialGridContents;
         	   }

         	   public static String seededWith(String gridContents) {
         	   	   return gridContents;
         	   }

             public void createNextGeneration() {
             }

             public String getGrid() {
                 return currentContent;
             }
         }
TDD in Action

       Well, now at least those two
               tests pass.




           public class Universe {

               private String currentContent;

           	   public Universe(String initialGridContents) {
           	       currentContent = initialGridContents;
           	   }

           	   public static String seededWith(String gridContents) {
           	   	   return gridContents;
           	   }

               public void createNextGeneration() {
               }

               public String getGrid() {
                   return currentContent;
               }
           }
TDD in Action

       Well, now at least those two
               tests pass.

                 Now we need to implement the
               ‘createNextGeneration()’ method...

           public class Universe {

               private String currentContent;

           	   public Universe(String initialGridContents) {
           	       currentContent = initialGridContents;
           	   }

           	   public static String seededWith(String gridContents) {
           	   	   return gridContents;
           	   }

               public void createNextGeneration() {
               }

               public String getGrid() {
                   return currentContent;
               }
           }
TDD for unbelievers


              So TDD is the answer to all my problems?


                No, sorry, TDD is not a Silver Bullet


You still have to use your brain
 Also use other design activities (domain modeling, DDD,...)
TDD is not applicable everywhere
 Highly visual coding, ‘know it when you see it’ stuff,...
TDD works best if you have a vision
TDD for unbelievers

             But how can I write tests if I don’t know what the code looks like?


                   How can you write code when you can’t express what it
                                        should do?


 “Write code for others as you would have them write code for you”
                                                             - Some agile dude



TDD is about expressing the intent of your code
It is a design practice
Design your code “outside-in”
TDD for unbelievers


                          I don’t have time to write tests

                  But you have time to fix the code afterwards, right?


      “I can get it done much faster if it doesn’t have to work”
                                                      - Kent Beck (paraphrased)



New TDDers will take maybe 20-30% longer
Experienced TDD developers don’t spend much (if any)
more time coding
But the code is of much higher quality
TDD for unbelievers


              But I'm writing more test code than application code!

                Sure, writing tests is part of the process


You will write lots of tests...
...but your code will be more focused and more accurate
TDD for unbelievers


                 My tests break whenever I change my code

                  Try to test the behaviour, not the implementation


Validate behaviour, don’t verify implementation
TDD for unbelievers


           Our tests are too hard and take too much time to keep up to date

                        Treat your test code as production code


Be wary of test maintenance overhead
 Test code is not second-class code
 Refactor to keep your test code maintanable
 Avoid technical dept
TDD for unbelievers


                 I found a bug in the production code. TDD doesn’t work.

                              see “TDD is not a Silver Bullet”


You still need your testers!
  You can still make mistakes...
  ...but they are easier to isolate and to fix
  If you find a bug, just add another test to reproduce it, then fix it!
TDD for unbelievers

             I’ve heard TDD encourages sloppy design. Isn't it better to have a
                  general vision of the problem before coding the solution?"

                   Sometimes, yes. That's what the refactoring phase is for.


TDD does not preclude initial high-level design
  Brainstorm a high-level design approach
  Define a common well-known domain language
  Use an ‘Iteration 0’ and spikes
  Don’t be afraid to refactor
TDD works better when you have a vision
TDD for unbelievers

             I use a database/network/web service... and TDD-style unit tests
                              can't test it. TDD doesn't work

                              You will need integration tests too


Unit tests when you can, integrations tests when you must
  Integration tests for system boundaries
  Mock out these boundary classes for the rest of your tests
TDD for unbelievers


                   Our BAs and product owners aren’t buying this TDD stuff

                                Try putting them into the feedback loop


Acceptance-Test Driven Development is about communication
 BDD help BAs and POs participate in writing executable requirements
 scenario "A cell with less than 2 live neighbours should die", {
 	   given "Given a cell with no live neighbours",
 	   when "a new generation is generated",
 	   then "that cell will have died"
 }
TDD for unbelievers


                   Our BAs and product owners aren’t buying this TDD stuff

                                Try putting them into the feedback loop


Acceptance-Test Driven Development is about communication
 BDD help BAs and POs participate in writing executable requirements
 scenario "A cell with less than 2 live neighbours should die", {
 	   given "Given a cell with no live neighbours", {
 	   	   initialGrid = ""...
 	   	                   .*.
 	   	                   ...""
 	   	   theUniverse = new Universe(seededWith(initialGrid));
 	   }
 	   when "a new generation is generated", {
 	   	   theUniverse.createNextGeneration()
 	   }
 	   then "that cell will have died", {
 	   	   theUniverse.grid.shouldBe ""...
 	   	   	   	   	  	   	   	  	   ...
 	   	   	   	   	  	   	   	  	   ...""
 	   }
 }
TDD for unbelievers


                   Our BAs and product owners aren’t buying this TDD stuff

                                Try putting them into the feedback loop


Acceptance-Test Driven Development is about communication
 BDD help BAs and POs participate in writing executable requirements
 Given a living cell with no live neighbours like this
 ...
 .*.
 ...
 When a new generation is generated
 then the grid should look like this:
 ...
 ...
 ...
TDD for unbelievers

           Many BDD tools also have great reporting features




                                     Test results summary

                                         Unimplemented stories



                                             Failed stories
TDD for unbelievers

            Many BDD tools have great reporting features

                                                Test results summary




                                                     Test failure details




                                             Unimplemented stories
TDD for unbelievers


            “I’ve tried TDD, but I soon lapse back into my old code-first habits”

                      TDD takes practice and know-how


Unit tests when you can, integrations tests when you must
  Learn about TDD - read books on TDD practices
  Do pair program with someone who knows TDD
  Participate in and organize coding dojos
  <blatant plug>Training/mentoring</blatant plug>
Conclusion
Real Developers Don’t Need Unit Tests?




            So maybe Chuck should be writing
                  unit tests after all...




              I agree. You go talk to him
Thank You



     John Ferguson Smart
     Wakaleo Consulting Ltd.
     http://www.wakaleo.com
     Email: john.smart@wakaleo.com
     Twitter: wakaleo

More Related Content

What's hot

Continuous code quality_in_java
Continuous code quality_in_javaContinuous code quality_in_java
Continuous code quality_in_javaManimekalai48
 
Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software testerAnton Keks
 
Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)Peter Kofler
 
How To Improve Quality With Static Code Analysis
How To Improve Quality With Static Code Analysis How To Improve Quality With Static Code Analysis
How To Improve Quality With Static Code Analysis Perforce
 
Code review best practice
Code review best practiceCode review best practice
Code review best practiceOren Digmi
 
Continuous inspection with Sonar
Continuous inspection with SonarContinuous inspection with Sonar
Continuous inspection with Sonargaudol
 
Don't let your tests slow you down
Don't let your tests slow you downDon't let your tests slow you down
Don't let your tests slow you downDaniel Irvine
 
Clean Software Design - DevNot Summit Istanbul 2017
Clean Software Design - DevNot Summit Istanbul 2017Clean Software Design - DevNot Summit Istanbul 2017
Clean Software Design - DevNot Summit Istanbul 2017Lemi Orhan Ergin
 
Code Review
Code ReviewCode Review
Code Reviewrantav
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016Søren Lund
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...VincitOy
 
Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Lemi Orhan Ergin
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Søren Lund
 
Code Review
Code ReviewCode Review
Code ReviewTu Hoang
 
Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidElvis Jon Freddy Sitinjak
 
Developer Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and ArquillianDeveloper Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and ArquillianRay Ploski
 

What's hot (20)

Sonar
Sonar Sonar
Sonar
 
Continuous code quality_in_java
Continuous code quality_in_javaContinuous code quality_in_java
Continuous code quality_in_java
 
Being a professional software tester
Being a professional software testerBeing a professional software tester
Being a professional software tester
 
Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)Concepts of Functional Programming for Java Brains (2010)
Concepts of Functional Programming for Java Brains (2010)
 
How To Improve Quality With Static Code Analysis
How To Improve Quality With Static Code Analysis How To Improve Quality With Static Code Analysis
How To Improve Quality With Static Code Analysis
 
Code review best practice
Code review best practiceCode review best practice
Code review best practice
 
Continuous inspection with Sonar
Continuous inspection with SonarContinuous inspection with Sonar
Continuous inspection with Sonar
 
Don't let your tests slow you down
Don't let your tests slow you downDon't let your tests slow you down
Don't let your tests slow you down
 
Clean Software Design - DevNot Summit Istanbul 2017
Clean Software Design - DevNot Summit Istanbul 2017Clean Software Design - DevNot Summit Istanbul 2017
Clean Software Design - DevNot Summit Istanbul 2017
 
Zend Di in ZF 2.0
Zend Di in ZF 2.0Zend Di in ZF 2.0
Zend Di in ZF 2.0
 
Code Review
Code ReviewCode Review
Code Review
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
 
Effective code reviews
Effective code reviewsEffective code reviews
Effective code reviews
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
 
Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016Test Driven Design - GDG DevFest Istanbul 2016
Test Driven Design - GDG DevFest Istanbul 2016
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016
 
Effective code reviews
Effective code reviewsEffective code reviews
Effective code reviews
 
Code Review
Code ReviewCode Review
Code Review
 
Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-android
 
Developer Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and ArquillianDeveloper Productivity with Forge, Java EE 6 and Arquillian
Developer Productivity with Forge, Java EE 6 and Arquillian
 

Viewers also liked

Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentDhaval Dalal
 
How Do Non-Clustered Indexes Improve Performance?
How Do Non-Clustered Indexes Improve Performance?How Do Non-Clustered Indexes Improve Performance?
How Do Non-Clustered Indexes Improve Performance?Jason Strate
 
Introduction to Clustered Indexes and Heaps
Introduction to Clustered Indexes and HeapsIntroduction to Clustered Indexes and Heaps
Introduction to Clustered Indexes and HeapsJason Strate
 
Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012
Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012
Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012Alexandre Morgaut
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexingMahabubur Rahaman
 
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?Mohamed Amine HAMDAOUI
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 

Viewers also liked (10)

Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
How Do Non-Clustered Indexes Improve Performance?
How Do Non-Clustered Indexes Improve Performance?How Do Non-Clustered Indexes Improve Performance?
How Do Non-Clustered Indexes Improve Performance?
 
Introduction to Clustered Indexes and Heaps
Introduction to Clustered Indexes and HeapsIntroduction to Clustered Indexes and Heaps
Introduction to Clustered Indexes and Heaps
 
Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012
Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012
Wakanda: NoSQL for Model-Driven Web applications - NoSQL matters 2012
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexing
 
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
Microsoft dynamics ax2012 : forms and tables methods call sequences, How To?
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 

Similar to Real Developers Don't Need Unit Tests

Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Danny Preussler
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-testsSkills Matter
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-testsSkills Matter
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference CardSeapine Software
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit TestingShaun Abram
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDDArati Joshi
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) CodeOps Technologies LLP
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012Justin Gordon
 
BDD presentation
BDD presentationBDD presentation
BDD presentationtemebele
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDDavid Rodenas
 
Agile Software Design
Agile Software DesignAgile Software Design
Agile Software Designeduardomg23
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is ImportaintSana Nasar
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentbhochhi
 

Similar to Real Developers Don't Need Unit Tests (20)

Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)Test Driven Development on Android (Kotlin Kenya)
Test Driven Development on Android (Kotlin Kenya)
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-testsReal developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
 
Test-Driven Development Reference Card
Test-Driven Development Reference CardTest-Driven Development Reference Card
Test-Driven Development Reference Card
 
Tdd red-green-refactor
Tdd red-green-refactorTdd red-green-refactor
Tdd red-green-refactor
 
Software Quality via Unit Testing
Software Quality via Unit TestingSoftware Quality via Unit Testing
Software Quality via Unit Testing
 
Pair programming and introduction to TDD
Pair programming and introduction to TDDPair programming and introduction to TDD
Pair programming and introduction to TDD
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
BDD presentation
BDD presentationBDD presentation
BDD presentation
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
 
Tdd and-bdd
Tdd and-bddTdd and-bdd
Tdd and-bdd
 
Agile Software Design
Agile Software DesignAgile Software Design
Agile Software Design
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Code detox
Code detoxCode detox
Code detox
 

More from John Ferguson Smart Limited

My Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin ScenariosMy Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin ScenariosJohn Ferguson Smart Limited
 
Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...John Ferguson Smart Limited
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceJohn Ferguson Smart Limited
 
Sustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and ScreenplaySustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and ScreenplayJohn Ferguson Smart Limited
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceJohn Ferguson Smart Limited
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...John Ferguson Smart Limited
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...John Ferguson Smart Limited
 
Screenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testingScreenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testingJohn Ferguson Smart Limited
 
All the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practicesAll the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practicesJohn Ferguson Smart Limited
 
It's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for TestersIt's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for TestersJohn Ferguson Smart Limited
 

More from John Ferguson Smart Limited (20)

My Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin ScenariosMy Reading Specs - Refactoring Patterns for Gherkin Scenarios
My Reading Specs - Refactoring Patterns for Gherkin Scenarios
 
Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...Artisti e Condotierri - How can your team become artists of the 21st century ...
Artisti e Condotierri - How can your team become artists of the 21st century ...
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a difference
 
BE A POD OF DOLPHINS, NOT A DANCING ELEPHANT
BE A POD OF DOLPHINS, NOT A DANCING ELEPHANTBE A POD OF DOLPHINS, NOT A DANCING ELEPHANT
BE A POD OF DOLPHINS, NOT A DANCING ELEPHANT
 
Sustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and ScreenplaySustainable Test Automation with Serenity BDD and Screenplay
Sustainable Test Automation with Serenity BDD and Screenplay
 
Feature Mapping Workshop
Feature Mapping WorkshopFeature Mapping Workshop
Feature Mapping Workshop
 
Engage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a differenceEngage! Bringing teams together to deliver software that makes a difference
Engage! Bringing teams together to deliver software that makes a difference
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
 
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
Beyond Given/When/Then - why diving into Cucumber is the wrong approach to ad...
 
Shift left-devoxx-pl
Shift left-devoxx-plShift left-devoxx-pl
Shift left-devoxx-pl
 
Screenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testingScreenplay - Next generation automated acceptance testing
Screenplay - Next generation automated acceptance testing
 
Cucumber and Spock Primer
Cucumber and Spock PrimerCucumber and Spock Primer
Cucumber and Spock Primer
 
All the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practicesAll the world's a stage – the next step in automated testing practices
All the world's a stage – the next step in automated testing practices
 
CukeUp 2016 Agile Product Planning Workshop
CukeUp 2016 Agile Product Planning WorkshopCukeUp 2016 Agile Product Planning Workshop
CukeUp 2016 Agile Product Planning Workshop
 
BDD Anti-patterns
BDD Anti-patternsBDD Anti-patterns
BDD Anti-patterns
 
Serenity and the Journey Pattern
Serenity and the Journey PatternSerenity and the Journey Pattern
Serenity and the Journey Pattern
 
BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!BDD - Collaborate like you mean it!
BDD - Collaborate like you mean it!
 
BDD-Driven Microservices
BDD-Driven MicroservicesBDD-Driven Microservices
BDD-Driven Microservices
 
BDD Anti-patterns
BDD Anti-patternsBDD Anti-patterns
BDD Anti-patterns
 
It's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for TestersIt's Testing, Jim, but not as we know it - BDD for Testers
It's Testing, Jim, but not as we know it - BDD for Testers
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Real Developers Don't Need Unit Tests

  • 1. Real Developers Don’t Need Unit Tests Mythbusting TDD myths John Ferguson Smart Wakaleo Consulting Ltd. http://www.wakaleo.com Email: john.smart@wakaleo.com Twitter: wakaleo
  • 3. Introduction Real Developers Don’t Need Unit Tests Bugs?
  • 4. Introduction Real Developers Don’t Need Unit Tests Bugs? Chuck Norris’s code doesn’t have bugs
  • 5. Introduction Real Developers Don’t Need Unit Tests Bugs? Chuck Norris’s code doesn’t have bugs His code always work. ALWAYS.
  • 6. Introduction Real Developers Don’t Need Unit Tests Bugs?
  • 7. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design?
  • 8. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Chuck Norris’s code is perfectly designed the first time round
  • 9. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Chuck Norris’s code is perfectly designed the first time round His favorite design pattern is the Roundhouse Kick
  • 10. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design?
  • 11. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation?
  • 12. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Chuck Norris doesn’t need technical documentation
  • 13. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Chuck Norris doesn’t need technical documentation He just stares down the code until it tells him everything he wants to know
  • 14. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation?
  • 15. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements?
  • 16. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements? Chuck Norris doesn’t need requirements to be executable
  • 17. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements? Chuck Norris doesn’t need requirements to be executable He can execute whatever he wants
  • 18. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements?
  • 19. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements? Acceptance Tests?
  • 20. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements? Acceptance Tests? Chuck Norris doesn’t need acceptance tests
  • 21. Introduction Real Developers Don’t Need Unit Tests Bugs? Emergent design? Technical documentation? Executable requirements? Acceptance Tests? Chuck Norris doesn’t need acceptance tests No one refuses to accept Chuck
  • 23. Introduction Real Developers Don’t Need Unit Tests OK, so Chuck Norris doesn’t need Unit Tests
  • 24. Introduction Real Developers Don’t Need Unit Tests OK, so Chuck Norris doesn’t need Unit Tests But what about the rest of us?
  • 26. TDD Basics So what is this TDD thing, anyway?
  • 27. TDD Basics TDD is not about writing tests So what is this TDD thing, anyway?
  • 28. TDD Basics TDD is not about writing tests TDD is a design strategy: So what is this TDD thing, anyway?
  • 29. TDD Basics TDD is not about writing tests TDD is a design strategy: Write better-designed code So what is this TDD thing, anyway?
  • 30. TDD Basics TDD is not about writing tests TDD is a design strategy: Write better-designed code Have more confidence in our code So what is this TDD thing, anyway?
  • 31. TDD Basics TDD is not about writing tests TDD is a design strategy: Write better-designed code Have more confidence in our code Make changes more easily So what is this TDD thing, anyway?
  • 32. TDD Basics TDD is not about writing tests TDD is a design strategy: Write better-designed code Have more confidence in our code Make changes more easily Write code that meets user requirements more accurately So what is this TDD thing, anyway?
  • 33. TDD Basics TDD is not about writing tests TDD is a design strategy: Write better-designed code Have more confidence in our code Make changes more easily Write code that meets user requirements more accurately (and incidentally...) So what is this TDD thing, anyway?
  • 34. TDD Basics TDD is not about writing tests TDD is a design strategy: Write better-designed code Have more confidence in our code Make changes more easily Write code that meets user requirements more accurately (and incidentally...) Build up a comprehensive set of automated tests So what is this TDD thing, anyway?
  • 35. TDD Basics The TDD development process “Never write a single line of code unless you have a failing automated test. Eliminate duplication.” - Kent Beck
  • 36. TDD Basics The TDD development process “Never write a single line of code unless you have a failing automated test. Eliminate duplication.” - Kent Beck TEST Write a failing unit test. Ensure that it fails.
  • 37. TDD Basics The TDD development process “Never write a single line of code unless you have a failing automated test. Eliminate duplication.” - Kent Beck TEST Write a failing unit test. Ensure that it fails. CODE Write production code to make the test pass.
  • 38. TDD Basics The TDD development process “Never write a single line of code unless you have a failing automated test. Eliminate duplication.” - Kent Beck TEST Write a failing unit test. Ensure that it fails. CODE Write production code to make the test pass. REFACTOR Tidy up the design
  • 39. TDD Basics TEST CODE REFACTOR
  • 40. TDD Basics Step 1) Write a test TEST CODE REFACTOR
  • 41. TDD Basics Step 1) Write a test TEST Design your code from the outside-in CODE REFACTOR
  • 42. TDD Basics Step 1) Write a test TEST Design your code from the outside-in How will your code be used? CODE REFACTOR
  • 43. TDD Basics Step 1) Write a test TEST Design your code from the outside-in How will your code be used? CODE Design a clean interface for your code REFACTOR
  • 44. TDD Basics Step 1) Write a test TEST Design your code from the outside-in How will your code be used? CODE Design a clean interface for your code Implement only features that are really needed REFACTOR
  • 45. TDD Basics Step 1) Write a test TEST Design your code from the outside-in How will your code be used? CODE Design a clean interface for your code Implement only features that are really needed REFACTOR Provide examples of how you expect your code to be used
  • 46. TDD Basics Step 1) Write a test TEST Design your code from the outside-in How will your code be used? CODE Design a clean interface for your code Implement only features that are really needed REFACTOR Provide examples of how you expect your code to be used How will my code be used by the rest of the application? ?
  • 47. TDD Basics TEST CODE REFACTOR
  • 48. TDD Basics Step 2) Write some code TEST CODE REFACTOR
  • 49. TDD Basics Step 2) Write some code TEST Just enough code to make the tests pass CODE REFACTOR
  • 50. TDD Basics Step 2) Write some code TEST Just enough code to make the tests pass Might mean a non-optimal solution at this stage... CODE REFACTOR
  • 51. TDD Basics Step 2) Write some code TEST Just enough code to make the tests pass Might mean a non-optimal solution at this stage... CODE REFACTOR Just make it pass the test...
  • 52. TDD Basics TEST CODE REFACTOR
  • 53. TDD Basics TEST CODE REFACTOR It works. Now let’s tidy things up.
  • 54. TDD Basics Step 3) Tidy up TEST CODE REFACTOR It works. Now let’s tidy things up.
  • 55. TDD Basics Step 3) Tidy up TEST Evolutionary (emerging) design CODE REFACTOR It works. Now let’s tidy things up.
  • 56. TDD Basics Step 3) Tidy up TEST Evolutionary (emerging) design Keep the code clean! CODE REFACTOR It works. Now let’s tidy things up.
  • 57. TDD Basics Step 3) Tidy up TEST Evolutionary (emerging) design Keep the code clean! CODE Remove duplication and fix design problems REFACTOR It works. Now let’s tidy things up.
  • 58. TDD Basics Step 3) Tidy up TEST Evolutionary (emerging) design Keep the code clean! CODE Remove duplication and fix design problems Restructure existing code - no new features! REFACTOR It works. Now let’s tidy things up.
  • 59. TDD Basics Step 3) Tidy up TEST Evolutionary (emerging) design Keep the code clean! CODE Remove duplication and fix design problems Restructure existing code - no new features! REFACTOR Make sure the tests still pass! It works. Now let’s tidy things up.
  • 60. TDD in Action - the Game Of Life
  • 61. TDD in Action - the Game Of Life So where do we start?
  • 62. TDD in Action - the Game Of Life So where do we start? Let’s list some requirements
  • 63. TDD in Action - the Game Of Life So where do we start? Let’s list some requirements The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live cells with 2 or 3 live neighbours remain alive - Dead cells with 3 neighbours become alive
  • 64. TDD in Action The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live User Story 1or Less than 2 neighbours die cells with 2 - 3 live neighbours remain alive - Dead cells cell with less than 2 live neighbours Given a with 3 neighbours become alive When the next generation is created Then this cell will die
  • 65. TDD in Action Now what? The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live User Story 1or Less than 2 neighbours die cells with 2 - 3 live neighbours remain alive - Dead cells cell with less than 2 live neighbours Given a with 3 neighbours become alive When the next generation is created Then this cell will die
  • 66. TDD in Action Now what? So what do we mean by this first requirement? The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live User Story 1or Less than 2 neighbours die cells with 2 - 3 live neighbours remain alive - Dead cells cell with less than 2 live neighbours Given a with 3 neighbours become alive When the next generation is created Then this cell will die
  • 67. TDD in Action The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live User Story 1or Less than 2 neighbours die cells with 2 - 3 live neighbours remain alive - Dead cells cell with less than 2 live neighbours Given a with 3 neighbours become alive When the next generation is created Then this cell will die
  • 68. TDD in Action So what do we have to code for this one. The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live User Story 1or Less than 2 neighbours die cells with 2 - 3 live neighbours remain alive - Dead cells cell with less than 2 live neighbours Given a with 3 neighbours become alive When the next generation is created Then this cell will die
  • 69. TDD in Action So what do we have to code for this one. Dunno yet. Let’s write some acceptance tests to find out The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live User Story 1or Less than 2 neighbours die cells with 2 - 3 live neighbours remain alive - Dead cells cell with less than 2 live neighbours Given a with 3 neighbours become alive When the next generation is created Then this cell will die
  • 70. TDD in Action So what do we have to code for this one. Dunno yet. Let’s write some acceptance tests to find out The Game of Life - Live cells with less than 2 live neighbours die - Live cells with more than 3 live neighbours die - Live UserUser StoryLessAcceptance criteria die cells Story 1or 3 live neighbours remain alive with 2 - 1 - than 2 neighbours - Dead cells cell with less than 2 live neighbours Given a with 3 neighbours become alive Sample grid transitions: 1) 2) When the next generation is created Then this cell will die
  • 72. TDD in Action Great, so now I can start coding, right?
  • 73. TDD in Action Great, so now I can start coding, right? Not so fast, hot shot. We need to turn this into an ‘executable requirement’
  • 74. TDD in Action Great, so now I can start coding, right? Not so fast, hot shot. We need to turn this into an ‘executable requirement’ public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { } }
  • 75. TDD in Action public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { } }
  • 76. TDD in Action I still don’t know what to write in this test... public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { } }
  • 77. TDD in Action I still don’t know what to write in this test... Start by expressing what you are trying to achieve public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { } }
  • 78. TDD in Action I still don’t know what to write in this test... Start by expressing what you are trying to achieve public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; String nextGrid = null; assertThat(nextGrid, is(expectedNextGrid)); } }
  • 79. TDD in Action public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; String nextGrid = null; assertThat(nextGrid, is(expectedNextGrid)); } }
  • 80. TDD in Action But that test will fail! What now? public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; String nextGrid = null; assertThat(nextGrid, is(expectedNextGrid)); } }
  • 81. TDD in Action But that test will fail! What now? How you would like the code to look, if you had to use it? public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; String nextGrid = null; assertThat(nextGrid, is(expectedNextGrid)); } }
  • 82. TDD in Action But that test will fail! What now? How you would like the code to look, if you had to use it? public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 83. TDD in Action public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 84. TDD in Action So what’s so special about this test? public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 85. TDD in Action So what’s so special about this test? The test name describes the expected behaviour public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 86. TDD in Action So what’s so special about this test? The test name describes the expected behaviour public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } } We started by expressing our expectations
  • 87. TDD in Action So what’s so special about this test? The test name describes the expected behaviour public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + The code is written for API "...n" + users, not API developers "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } } We started by expressing our expectations
  • 88. TDD in Action So what’s so special about this test? The test name describes the expected behaviour public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; It’s a working String expectedNextGrid = "...n" + The code is written for API example of how "...n" + users, not API developers to use the class "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } } We started by expressing our expectations
  • 89. TDD in Action public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 90. TDD in Action So what now? public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 91. TDD in Action So what now? This is our acceptance test. Now we drill down. public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 92. TDD in Action So what now? This is our acceptance test. Now we drill down. public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 93. TDD in Action public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 94. TDD in Action So I guess you’ll say we need to write a test? public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 95. TDD in Action So I guess you’ll say we need to write a test? Spot on! You catch on fast! public class GameOfLifeTest { @Test public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { String initialGrid = "...n" + "...n" + "..."; String expectedNextGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 96. TDD in Action So I guess you’ll say we need to write a test? Spot on! You catch on fast! public class UniverseTest { @Test public class GameOfLifeTest { public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() { @Test String seededGrid = "...n" + public void aCellWithNoNeighboursShouldDieInTheNextGeneration() { "...n" + String initialGrid = "...n" + "..."; "...n" + "..."; Universe theUniverse = new Universe(seededWith(seededGrid)); String currentGrid = theUniverse.getGrid(); String expectedNextGrid = "...n" + assertThat(currentGrid, is(seededGrid)); "...n" + } "..."; } Universe theUniverse = new Universe(seededWith(initialGrid)); theUniverse.createNextGeneration(); String nextGrid = theUniverse.getGrid(); assertThat(nextGrid, is(expectedNextGrid)); } }
  • 97. TDD in Action public class UniverseTest { @Test public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() { String seededGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(seededGrid)); String currentGrid = theUniverse.getGrid(); assertThat(currentGrid, is(seededGrid)); } }
  • 98. TDD in Action So now can we code? public class UniverseTest { @Test public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() { String seededGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(seededGrid)); String currentGrid = theUniverse.getGrid(); assertThat(currentGrid, is(seededGrid)); } }
  • 99. TDD in Action So now can we code? Yes, but just a little bit public class UniverseTest { @Test public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() { String seededGrid = "...n" + "...n" + "..."; Universe theUniverse = new Universe(seededWith(seededGrid)); String currentGrid = theUniverse.getGrid(); assertThat(currentGrid, is(seededGrid)); } }
  • 100. TDD in Action So now can we code? Yes, but just a little bit public class UniverseTest { @Test public class Universe { public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() { public Universe(String initialGridContents) {} String seededGrid = "...n" + public static String seededWith(String gridContents) { "...n" + return null; "..."; } Universe theUniverse = new Universe(seededWith(seededGrid)); public void createNextGeneration() {} String currentGrid = theUniverse.getGrid(); assertThat(currentGrid, is(seededGrid)); } public String getGrid() { } return "...n" + "...n" + "..."; } }
  • 102. TDD in Action Er, isn’t that a bit too simple.
  • 103. TDD in Action Er, isn’t that a bit too simple. Yes. We need another test to tease out a more complete design
  • 104. TDD in Action Er, isn’t that a bit too simple. Yes. We need another test to tease out a more complete design public class UniverseTest { @Test public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {...} @Test public void aUniverseSeededWithANonEmpyGridContentWillContainThatGrid() { String seededGrid = "...n" + ".*.n" + "..."; Universe theUniverse = new Universe(seededWith(seededGrid)); String currentGrid = theUniverse.getGrid(); assertThat(currentGrid, is(seededGrid)); } }
  • 105. TDD in Action Er, isn’t that a bit too simple. Yes. We need another test to tease out a more complete design public class UniverseTest { @Test public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {...} @Test public void aUniverseSeededWithANonEmpyGridContentWillContainThatGrid() { String seededGrid = "...n" + ".*.n" + "..."; Universe theUniverse = new Universe(seededWith(seededGrid)); String currentGrid = theUniverse.getGrid(); assertThat(currentGrid, is(seededGrid)); } }
  • 106. TDD in Action Er, isn’t that a bit too simple. Yes. We need another test to tease out a more complete design public class Universe { public class UniverseTest { private String currentContent; @Test public Universe(String initialGridContents) { public void aUniverseSeededWithAnEmpyGridContentWillContainAnEmptyGrid() {...} currentContent = initialGridContents; } @Test public void aUniverseSeededWithANonEmpyGridContentWillContainThatGrid() { public static String seededWith(String gridContents) { return gridContents; String seededGrid = "...n" + } ".*.n" + "..."; public void createNextGeneration() { } Universe theUniverse = new Universe(seededWith(seededGrid)); String currentGrid = theUniverse.getGrid(); public String getGrid() { assertThat(currentGrid, is(seededGrid)); return currentContent; } } } }
  • 107. TDD in Action public class Universe { private String currentContent; public Universe(String initialGridContents) { currentContent = initialGridContents; } public static String seededWith(String gridContents) { return gridContents; } public void createNextGeneration() { } public String getGrid() { return currentContent; } }
  • 108. TDD in Action Well, now at least those two tests pass. public class Universe { private String currentContent; public Universe(String initialGridContents) { currentContent = initialGridContents; } public static String seededWith(String gridContents) { return gridContents; } public void createNextGeneration() { } public String getGrid() { return currentContent; } }
  • 109. TDD in Action Well, now at least those two tests pass. Now we need to implement the ‘createNextGeneration()’ method... public class Universe { private String currentContent; public Universe(String initialGridContents) { currentContent = initialGridContents; } public static String seededWith(String gridContents) { return gridContents; } public void createNextGeneration() { } public String getGrid() { return currentContent; } }
  • 110. TDD for unbelievers So TDD is the answer to all my problems? No, sorry, TDD is not a Silver Bullet You still have to use your brain Also use other design activities (domain modeling, DDD,...) TDD is not applicable everywhere Highly visual coding, ‘know it when you see it’ stuff,... TDD works best if you have a vision
  • 111. TDD for unbelievers But how can I write tests if I don’t know what the code looks like? How can you write code when you can’t express what it should do? “Write code for others as you would have them write code for you” - Some agile dude TDD is about expressing the intent of your code It is a design practice Design your code “outside-in”
  • 112. TDD for unbelievers I don’t have time to write tests But you have time to fix the code afterwards, right? “I can get it done much faster if it doesn’t have to work” - Kent Beck (paraphrased) New TDDers will take maybe 20-30% longer Experienced TDD developers don’t spend much (if any) more time coding But the code is of much higher quality
  • 113. TDD for unbelievers But I'm writing more test code than application code! Sure, writing tests is part of the process You will write lots of tests... ...but your code will be more focused and more accurate
  • 114. TDD for unbelievers My tests break whenever I change my code Try to test the behaviour, not the implementation Validate behaviour, don’t verify implementation
  • 115. TDD for unbelievers Our tests are too hard and take too much time to keep up to date Treat your test code as production code Be wary of test maintenance overhead Test code is not second-class code Refactor to keep your test code maintanable Avoid technical dept
  • 116. TDD for unbelievers I found a bug in the production code. TDD doesn’t work. see “TDD is not a Silver Bullet” You still need your testers! You can still make mistakes... ...but they are easier to isolate and to fix If you find a bug, just add another test to reproduce it, then fix it!
  • 117. TDD for unbelievers I’ve heard TDD encourages sloppy design. Isn't it better to have a general vision of the problem before coding the solution?" Sometimes, yes. That's what the refactoring phase is for. TDD does not preclude initial high-level design Brainstorm a high-level design approach Define a common well-known domain language Use an ‘Iteration 0’ and spikes Don’t be afraid to refactor TDD works better when you have a vision
  • 118. TDD for unbelievers I use a database/network/web service... and TDD-style unit tests can't test it. TDD doesn't work You will need integration tests too Unit tests when you can, integrations tests when you must Integration tests for system boundaries Mock out these boundary classes for the rest of your tests
  • 119. TDD for unbelievers Our BAs and product owners aren’t buying this TDD stuff Try putting them into the feedback loop Acceptance-Test Driven Development is about communication BDD help BAs and POs participate in writing executable requirements scenario "A cell with less than 2 live neighbours should die", { given "Given a cell with no live neighbours", when "a new generation is generated", then "that cell will have died" }
  • 120. TDD for unbelievers Our BAs and product owners aren’t buying this TDD stuff Try putting them into the feedback loop Acceptance-Test Driven Development is about communication BDD help BAs and POs participate in writing executable requirements scenario "A cell with less than 2 live neighbours should die", { given "Given a cell with no live neighbours", { initialGrid = ""... .*. ..."" theUniverse = new Universe(seededWith(initialGrid)); } when "a new generation is generated", { theUniverse.createNextGeneration() } then "that cell will have died", { theUniverse.grid.shouldBe ""... ... ..."" } }
  • 121. TDD for unbelievers Our BAs and product owners aren’t buying this TDD stuff Try putting them into the feedback loop Acceptance-Test Driven Development is about communication BDD help BAs and POs participate in writing executable requirements Given a living cell with no live neighbours like this ... .*. ... When a new generation is generated then the grid should look like this: ... ... ...
  • 122. TDD for unbelievers Many BDD tools also have great reporting features Test results summary Unimplemented stories Failed stories
  • 123. TDD for unbelievers Many BDD tools have great reporting features Test results summary Test failure details Unimplemented stories
  • 124. TDD for unbelievers “I’ve tried TDD, but I soon lapse back into my old code-first habits” TDD takes practice and know-how Unit tests when you can, integrations tests when you must Learn about TDD - read books on TDD practices Do pair program with someone who knows TDD Participate in and organize coding dojos <blatant plug>Training/mentoring</blatant plug>
  • 125. Conclusion Real Developers Don’t Need Unit Tests? So maybe Chuck should be writing unit tests after all... I agree. You go talk to him
  • 126. Thank You John Ferguson Smart Wakaleo Consulting Ltd. http://www.wakaleo.com Email: john.smart@wakaleo.com Twitter: wakaleo