SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
(track sponsor)



 Common
   TDD
Mistakes &
  Pitfalls
Amir Barylko
AMIR BARYLKO
                     COMMON TDD
                   MISTAKES & PITFALLS
                                         PRAIRIE DEV CON
                                           REGINA 2011




Amir Barylko - TDD Mistakes & Pitfalls                     MavenThought Inc.
WHO AM I?

  • Architect

  • Developer

  • Mentor

  • Great      cook

  • The     one who’s entertaining you for the next hour!


Amir Barylko - TDD Mistakes & Pitfalls                      MavenThought Inc.
INTRO
                                         Why projects fail?
                                          Reality Check
                                         No more excuses
                                           Why TDD?



Amir Barylko - TDD Mistakes & Pitfalls                        MavenThought Inc.
WHY PROJECTS FAIL?

  • Delivering            late or over budget
  • Delivering            the wrong thing
  • Unstable            in production
  • Costly         to maintain


Amir Barylko - TDD Mistakes & Pitfalls          MavenThought Inc.
REALITY CHECK

  • It is impossible to gather all the requirements at
     the beginning of a project.
  • Whatever   requirements you do gather are
     guaranteed to change.
  • There will always be more to do than time and
     money will allow.

Amir Barylko - TDD Mistakes & Pitfalls         MavenThought Inc.
NO MORE EXCUSES

  • It   works on my computer!           • We need a satellite
                                          connection in order to
  • It was like that when I got           run it!
     here!
                                         • We can’t reproduce the
  • The   previous developer              error!
     didn’t know XXXX!
                                         • We   can’t test that!


Amir Barylko - TDD Mistakes & Pitfalls                        MavenThought Inc.
WHY TDD?

  • Prove         that your code         • Regression   tests as
     works                                byproduct
  • Avoid  waste                         • Makechanges with
     (debugging)                          confidence
  • Increment             code quality   • Bring
                                               back the joy of
                                          coding!
  • Better         design
Amir Barylko - TDD Mistakes & Pitfalls                     MavenThought Inc.
RED GREEN REFACTOR

  • Always       start with red

  • Minimum          amount of code to get green

  • Refactor       if necessary

  • Gain     confidence

  • When        in doubt, write a test


Amir Barylko - TDD Mistakes & Pitfalls             MavenThought Inc.
THE LIST




Amir Barylko - Common mistakes and pitfalls      MavenThought Inc.
TEST IDENTIFICATION

  • Unit

  • Integration

  • Acceptance

  • Which       one should I use?

  • What       are the limits?


Amir Barylko - TDD Mistakes & Pitfalls   MavenThought Inc.
UNIT
  public class When_movie_library_adds_a_movie
  {
      public void Should_include_all_the_movies_in_the_contents()
  }


  • One      class

  • One      method

  • No     dependencies



Amir Barylko - TDD Mistakes & Pitfalls                    MavenThought Inc.
INTEGRATION
  public class When_movie_library_sends_a_tweet
  {
      public void Should_send_a_tweet_with_new_movies()
  }


  • Two      or more classes

  • Validate      interaction between classes

  • Still   white box testing



Amir Barylko - TDD Mistakes & Pitfalls                    MavenThought Inc.
ACCEPTANCE
  Scenario:      Get presenters as JSON
    Given I      have some speakers at the conference
    When I       get "speakers" as JSON
    Then I       should get a response with all the speakers


  • Black     box testing
  • Manipulate         the application
  • Populate        the database with expected data
  • Validate      using the application values


Amir Barylko - TDD Mistakes & Pitfalls                         MavenThought Inc.
ONE SCENARIO PER TEST

  • Easy     to approach

  • Easy     to understand

  • Easy     to maintain




Amir Barylko - TDD Mistakes & Pitfalls   MavenThought Inc.
EVERYTHING TOGETHER
  [TestFixture]
  public class MovieLibraryTest
  {
      [Test]
      public void When_Initialized_Should_Be_Empty()

       [Test]
       public void When_Adding_Should_Appear_In_The_Contents()

       [Test]
       public void When_Adding_Should_Trigger_Event()

       [Test]
       public void When_ListingNV_Should_Ask_Critic()

       [Test]
       public void When_ListingNV_Should_Return_All_NV()

       [Test]
       public void When_ListingNV_Should_Throw_Exception_If_Missing_Critic()
  }


Amir Barylko - TDD Mistakes & Pitfalls                                         MavenThought Inc.
SCENARIO IDENTIFICATION

  1.Initialize                           3.Listing NV movies
    1.1.Library should be empty
                                          3.1.Missing Critic
  2.Addingd Movies                        3.2.Listing only NV
     2.1.Contents are changes

     2.2.Event is triggered



Amir Barylko - TDD Mistakes & Pitfalls                         MavenThought Inc.
ADDING MOVIES
  public class When_movie_library_adds_a_movie
  {
         public void Should_include_the_movie()


         public void Should_notify_an_element_was_added()
  }




Amir Barylko - TDD Mistakes & Pitfalls               MavenThought Inc.
LISTING NV MOVIES
  public class When_movie_library_list_nv_with_no_critic
  {
         public void Should_throw_missing_critic_exception()
  }



  public class When_movie_library_lists_nv_movies
  {
      public void Should_return_all_the_nv_movies()
  }



Amir Barylko - TDD Mistakes & Pitfalls               MavenThought Inc.
WHO’S YOUR DD?

  • Quality      Driver

  • Use     the methodology

  • Gain     confidence

  • Don’t      show off




Amir Barylko - TDD Mistakes & Pitfalls   MavenThought Inc.
THE TEST
  public class When_creating_cells
  {
      public void Should_not_be_alive()
      {
          var cell = new Cell();

                cell.Alive.Should().Be.False();
         }
  }




Amir Barylko - TDD Mistakes & Pitfalls              MavenThought Inc.
MAKE IT PASS

  • Minimum          amount of code      public class Cell
                                         {
  • Don’t      think about what’s            public bool Alive
                                             {
     next                                        get { return xxxx? }
                                             }
  • One      bit of code at a time       }

  • Let    the technology drive

  • Now, make           it fail!

Amir Barylko - TDD Mistakes & Pitfalls                      MavenThought Inc.
BEHAVIOUR VERIFICATION

  • Test    setters and getters

  • Verify     the dependencies called

  • Test    private members

  • How       do I know when’s enough?




Amir Barylko - TDD Mistakes & Pitfalls   MavenThought Inc.
TESTING THE CALL
  public class When_movie_library_lists_nv_movies
  {
      public void Should_return_all_the_nv_movies()

         public void Should_call_the_critic_3_times()
  }




Amir Barylko - TDD Mistakes & Pitfalls                  MavenThought Inc.
SPECIFY BEHAVIOUR

  • Avoid      testing implementation

  • Setup      all the behaviour

  • Find    the scenario that fails

  • Test    calls if can’t be verified otherwise




Amir Barylko - TDD Mistakes & Pitfalls            MavenThought Inc.
LACK OF AUTOMATION

  • Who       runs the test?

  • Who’s       in charge of deployment?

  • Who       enforces policies on commit?

  • Where’s        the documentation?

  • Do     I need the IDE in order to build?


Amir Barylko - TDD Mistakes & Pitfalls         MavenThought Inc.
ITERATION 0

  • Run     all the tests since day one

  • Commit         should trigger build

  • Build     should trigger test

  • Test    may trigger deploy

  • Scripts     should run locally


Amir Barylko - TDD Mistakes & Pitfalls        MavenThought Inc.
LEGACY CODE

  • The     code is a mess

  • Can’t     refactor easily

  • No     documentation

  • No     testing

  • Who       dares to make a change?


Amir Barylko - TDD Mistakes & Pitfalls    MavenThought Inc.
WHAT TO DO?

  • Acceptance          tests to document current features

  • Migrations        to capture current database

  • Migrations        to capture changes and population

  • Unit     test works better for new modifications




Amir Barylko - TDD Mistakes & Pitfalls                       MavenThought Inc.
DEPENDENCIES

  • Hardcoded           dependencies

  • Unit     or integration test?

  • Isolation




Amir Barylko - TDD Mistakes & Pitfalls    MavenThought Inc.
SOMETHING SMELLS
  public class MovieLibrary {

          private TwitterNotifier _notifier;

          public MovieLibrary() {

                 this._notifier = new TwitterNotifier();

          }

  }


Amir Barylko - TDD Mistakes & Pitfalls               MavenThought Inc.
EXTRACT DEPENDENCIES
  public class MovieLibrary {
         private INotifier _notifier;
         public MovieLibrary(INotifier notifier) {
                this._notifier = notifier;
         }
  }

  • Introduces        dependency in the constructor / setter

  • Easy     to test and maintain

Amir Barylko - TDD Mistakes & Pitfalls                         MavenThought Inc.
RANDOM VALUES

  • Are     u kidding?

  • How       do I know are the right values?

  • How       do I know is not going to fail the next one?




Amir Barylko - TDD Mistakes & Pitfalls                       MavenThought Inc.
TEST WITH PARAMETERS
                                         [Row(1)]
  • Avoid   duplication and              [Row(2)]
     repetition                          void Method(int arg)
                                         [Row(typeof(...))]
  • Generic       Parameters             void Method<T>(...)

  • Parameters          Factories        [Factory(...)]
                                         void Method(string arg)
  • Random         strings               void Method([Random]...)

  • Random         numbers               void Method([Random]...,
                                                     [Factory]...)

Amir Barylko - TDD Mistakes & Pitfalls                   MavenThought Inc.
QUESTIONS?




Amir Barylko - Common mistakes and pitfalls   MavenThought Inc.
RESOURCES

  • Contact        me: amir@barylko.com, @abarylko

  • Download: http://www.orhtocoders.com/presentations

  • Books: The         rSpec book, xUnit Patterns.




Amir Barylko - TDD Mistakes & Pitfalls               MavenThought Inc.
RESOURCES II

  • NUnit: http://www.nunit.org

  • Gallio     & MbUnit: http://www.gallio.org

  • MavenThought Testing: http://maventcommons.codeplex.com

  • Rhino      Mocks: http://www.ayende.com

  • StructureMap: http://structuremap.sourcefore.com

  • TeamCity: http://www.jetbrains.com

Amir Barylko - TDD Mistakes & Pitfalls                 MavenThought Inc.

Más contenido relacionado

La actualidad más candente

2012 regina TC 102 kanban
2012 regina TC 102 kanban2012 regina TC 102 kanban
2012 regina TC 102 kanbanAmir Barylko
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Mozaic Works
 
Flexing your Agile Muscle - Agile Technical Concepts Explained
Flexing your Agile Muscle - Agile Technical Concepts ExplainedFlexing your Agile Muscle - Agile Technical Concepts Explained
Flexing your Agile Muscle - Agile Technical Concepts ExplainedSandy Mamoli
 
every-day-automation
every-day-automationevery-day-automation
every-day-automationAmir Barylko
 
PRDCW-advanced-design-patterns
PRDCW-advanced-design-patternsPRDCW-advanced-design-patterns
PRDCW-advanced-design-patternsAmir Barylko
 
CPL12-Agile-planning
CPL12-Agile-planningCPL12-Agile-planning
CPL12-Agile-planningAmir Barylko
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integrationAmir Barylko
 
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockPragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockJoseph Yoder
 
Getting started with Agile
Getting started with AgileGetting started with Agile
Getting started with Agilekutuma
 
Test Driven Development via Agile Testing
Test Driven Development via Agile TestingTest Driven Development via Agile Testing
Test Driven Development via Agile TestingAnand Bagmar
 
Adapting Agility: Getting your Agile Transformation Unstuck
Adapting Agility: Getting your Agile Transformation UnstuckAdapting Agility: Getting your Agile Transformation Unstuck
Adapting Agility: Getting your Agile Transformation UnstuckCamille Bell
 
Testing an Erlang Backend
Testing an Erlang BackendTesting an Erlang Backend
Testing an Erlang Backendenriquepazperez
 
Inside Behavior Driven Development
Inside Behavior Driven DevelopmentInside Behavior Driven Development
Inside Behavior Driven DevelopmentCamille Bell
 
Growing Manual Testers into Automators
Growing Manual Testers into AutomatorsGrowing Manual Testers into Automators
Growing Manual Testers into AutomatorsCamille Bell
 
Continuous Context Driven Test Improvement
Continuous Context Driven Test ImprovementContinuous Context Driven Test Improvement
Continuous Context Driven Test ImprovementTechWell
 
Building Mobile (app) Masterpiece with Distributed Agile
Building Mobile (app) Masterpiece with Distributed AgileBuilding Mobile (app) Masterpiece with Distributed Agile
Building Mobile (app) Masterpiece with Distributed AgileWee Witthawaskul
 

La actualidad más candente (20)

obs-tdd-intro
obs-tdd-introobs-tdd-intro
obs-tdd-intro
 
2012 regina TC 102 kanban
2012 regina TC 102 kanban2012 regina TC 102 kanban
2012 regina TC 102 kanban
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 
Flexing your Agile Muscle - Agile Technical Concepts Explained
Flexing your Agile Muscle - Agile Technical Concepts ExplainedFlexing your Agile Muscle - Agile Technical Concepts Explained
Flexing your Agile Muscle - Agile Technical Concepts Explained
 
every-day-automation
every-day-automationevery-day-automation
every-day-automation
 
PRDCW-advanced-design-patterns
PRDCW-advanced-design-patternsPRDCW-advanced-design-patterns
PRDCW-advanced-design-patterns
 
CPL12-Agile-planning
CPL12-Agile-planningCPL12-Agile-planning
CPL12-Agile-planning
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-BrockPragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
Pragmatic Not Dogmatic TDD Agile2012 by Joseph Yoder and Rebecca Wirfs-Brock
 
Getting started with Agile
Getting started with AgileGetting started with Agile
Getting started with Agile
 
Test Driven Development via Agile Testing
Test Driven Development via Agile TestingTest Driven Development via Agile Testing
Test Driven Development via Agile Testing
 
Kanban intro
Kanban introKanban intro
Kanban intro
 
Adapting Agility: Getting your Agile Transformation Unstuck
Adapting Agility: Getting your Agile Transformation UnstuckAdapting Agility: Getting your Agile Transformation Unstuck
Adapting Agility: Getting your Agile Transformation Unstuck
 
Testing an Erlang Backend
Testing an Erlang BackendTesting an Erlang Backend
Testing an Erlang Backend
 
Inside Behavior Driven Development
Inside Behavior Driven DevelopmentInside Behavior Driven Development
Inside Behavior Driven Development
 
Growing Manual Testers into Automators
Growing Manual Testers into AutomatorsGrowing Manual Testers into Automators
Growing Manual Testers into Automators
 
Continuous Context Driven Test Improvement
Continuous Context Driven Test ImprovementContinuous Context Driven Test Improvement
Continuous Context Driven Test Improvement
 
Testing In Agile
Testing In AgileTesting In Agile
Testing In Agile
 
Building Mobile (app) Masterpiece with Distributed Agile
Building Mobile (app) Masterpiece with Distributed AgileBuilding Mobile (app) Masterpiece with Distributed Agile
Building Mobile (app) Masterpiece with Distributed Agile
 

Similar a PRDC11-tdd-common-mistakes

prdc10-tdd-patterns
prdc10-tdd-patternsprdc10-tdd-patterns
prdc10-tdd-patternsAmir Barylko
 
Leandro Melendez - Switching Performance Left & Right
Leandro Melendez - Switching Performance Left & RightLeandro Melendez - Switching Performance Left & Right
Leandro Melendez - Switching Performance Left & RightNeotys_Partner
 
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
 
Acceptance testfurureinmind
Acceptance testfurureinmindAcceptance testfurureinmind
Acceptance testfurureinmindLeanDog
 
What CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingWhat CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingCamille Bell
 
Battle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectBattle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectGlobalLogic Ukraine
 
Test Driven Development - Workshop
Test Driven Development - WorkshopTest Driven Development - Workshop
Test Driven Development - WorkshopAnjana Somathilake
 
Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)Peter Kofler
 
Unit testing for Cocoa developers
Unit testing for Cocoa developersUnit testing for Cocoa developers
Unit testing for Cocoa developersGraham Lee
 
Paving the Way for Agile Engineering Practices
Paving the Way for Agile Engineering PracticesPaving the Way for Agile Engineering Practices
Paving the Way for Agile Engineering PracticesAman King
 
Lessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From ZombielandLessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From ZombielandMatt Barbour
 
Continuous delivery is more than dev ops
Continuous delivery is more than dev opsContinuous delivery is more than dev ops
Continuous delivery is more than dev opsAgile Montréal
 
prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-worldAmir Barylko
 
No, we can't do continuous delivery
No, we can't do continuous deliveryNo, we can't do continuous delivery
No, we can't do continuous deliveryKris Buytaert
 
Finding the important bugs- A talk by John Scarborough, Director of Testing, ...
Finding the important bugs- A talk by John Scarborough, Director of Testing, ...Finding the important bugs- A talk by John Scarborough, Director of Testing, ...
Finding the important bugs- A talk by John Scarborough, Director of Testing, ...HARMAN Services
 
Patterns & Antipatterns in Docker Image Lifecycle
Patterns & Antipatterns in Docker Image LifecyclePatterns & Antipatterns in Docker Image Lifecycle
Patterns & Antipatterns in Docker Image Lifecycleyoavl
 
Scaling Continuous Integration Practices to Teams with Parallel Development
Scaling Continuous Integration Practices to Teams with Parallel DevelopmentScaling Continuous Integration Practices to Teams with Parallel Development
Scaling Continuous Integration Practices to Teams with Parallel DevelopmentIBM UrbanCode Products
 
Metrics-driven Continuous Delivery
Metrics-driven Continuous DeliveryMetrics-driven Continuous Delivery
Metrics-driven Continuous DeliveryAndrew Phillips
 

Similar a PRDC11-tdd-common-mistakes (20)

prdc10-tdd-patterns
prdc10-tdd-patternsprdc10-tdd-patterns
prdc10-tdd-patterns
 
Leandro Melendez - Switching Performance Left & Right
Leandro Melendez - Switching Performance Left & RightLeandro Melendez - Switching Performance Left & Right
Leandro Melendez - Switching Performance Left & Right
 
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)
 
Acceptance testfurureinmind
Acceptance testfurureinmindAcceptance testfurureinmind
Acceptance testfurureinmind
 
What CS Class Didn't Teach About Testing
What CS Class Didn't Teach About TestingWhat CS Class Didn't Teach About Testing
What CS Class Didn't Teach About Testing
 
Battle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectBattle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java Project
 
Test Driven Development - Workshop
Test Driven Development - WorkshopTest Driven Development - Workshop
Test Driven Development - Workshop
 
Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)
 
Unit testing for Cocoa developers
Unit testing for Cocoa developersUnit testing for Cocoa developers
Unit testing for Cocoa developers
 
Paving the Way for Agile Engineering Practices
Paving the Way for Agile Engineering PracticesPaving the Way for Agile Engineering Practices
Paving the Way for Agile Engineering Practices
 
Tec314
Tec314Tec314
Tec314
 
Lessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From ZombielandLessons Learned in Test Automation From Zombieland
Lessons Learned in Test Automation From Zombieland
 
Continuous delivery is more than dev ops
Continuous delivery is more than dev opsContinuous delivery is more than dev ops
Continuous delivery is more than dev ops
 
prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-world
 
No, we can't do continuous delivery
No, we can't do continuous deliveryNo, we can't do continuous delivery
No, we can't do continuous delivery
 
Core Principles Of Ci
Core Principles Of CiCore Principles Of Ci
Core Principles Of Ci
 
Finding the important bugs- A talk by John Scarborough, Director of Testing, ...
Finding the important bugs- A talk by John Scarborough, Director of Testing, ...Finding the important bugs- A talk by John Scarborough, Director of Testing, ...
Finding the important bugs- A talk by John Scarborough, Director of Testing, ...
 
Patterns & Antipatterns in Docker Image Lifecycle
Patterns & Antipatterns in Docker Image LifecyclePatterns & Antipatterns in Docker Image Lifecycle
Patterns & Antipatterns in Docker Image Lifecycle
 
Scaling Continuous Integration Practices to Teams with Parallel Development
Scaling Continuous Integration Practices to Teams with Parallel DevelopmentScaling Continuous Integration Practices to Teams with Parallel Development
Scaling Continuous Integration Practices to Teams with Parallel Development
 
Metrics-driven Continuous Delivery
Metrics-driven Continuous DeliveryMetrics-driven Continuous Delivery
Metrics-driven Continuous Delivery
 

Más de Amir Barylko

Functional converter project
Functional converter projectFunctional converter project
Functional converter projectAmir Barylko
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web developmentAmir Barylko
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep diveAmir Barylko
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting trainingAmir Barylko
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessAmir Barylko
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6Amir Barylko
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?Amir Barylko
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideAmir Barylko
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityAmir Barylko
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven DevelopmentAmir Barylko
 
Agile requirements
Agile requirementsAgile requirements
Agile requirementsAmir Barylko
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilitiesAmir Barylko
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescriptAmir Barylko
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptAmir Barylko
 

Más de Amir Barylko (20)

Functional converter project
Functional converter projectFunctional converter project
Functional converter project
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
No estimates
No estimatesNo estimates
No estimates
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep dive
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting training
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomeness
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Productive teams
Productive teamsProductive teams
Productive teams
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other side
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivity
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Refactoring
RefactoringRefactoring
Refactoring
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilities
 
Refactoring
RefactoringRefactoring
Refactoring
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
 
Sass & bootstrap
Sass & bootstrapSass & bootstrap
Sass & bootstrap
 
Rich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; CoffeescriptRich UI with Knockout.js &amp; Coffeescript
Rich UI with Knockout.js &amp; Coffeescript
 

Último

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Último (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

PRDC11-tdd-common-mistakes

  • 1. (track sponsor) Common TDD Mistakes & Pitfalls Amir Barylko
  • 2. AMIR BARYLKO COMMON TDD MISTAKES & PITFALLS PRAIRIE DEV CON REGINA 2011 Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 3. WHO AM I? • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour! Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 4. INTRO Why projects fail? Reality Check No more excuses Why TDD? Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 5. WHY PROJECTS FAIL? • Delivering late or over budget • Delivering the wrong thing • Unstable in production • Costly to maintain Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 6. REALITY CHECK • It is impossible to gather all the requirements at the beginning of a project. • Whatever requirements you do gather are guaranteed to change. • There will always be more to do than time and money will allow. Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 7. NO MORE EXCUSES • It works on my computer! • We need a satellite connection in order to • It was like that when I got run it! here! • We can’t reproduce the • The previous developer error! didn’t know XXXX! • We can’t test that! Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 8. WHY TDD? • Prove that your code • Regression tests as works byproduct • Avoid waste • Makechanges with (debugging) confidence • Increment code quality • Bring back the joy of coding! • Better design Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 9. RED GREEN REFACTOR • Always start with red • Minimum amount of code to get green • Refactor if necessary • Gain confidence • When in doubt, write a test Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 10. THE LIST Amir Barylko - Common mistakes and pitfalls MavenThought Inc.
  • 11. TEST IDENTIFICATION • Unit • Integration • Acceptance • Which one should I use? • What are the limits? Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 12. UNIT public class When_movie_library_adds_a_movie { public void Should_include_all_the_movies_in_the_contents() } • One class • One method • No dependencies Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 13. INTEGRATION public class When_movie_library_sends_a_tweet { public void Should_send_a_tweet_with_new_movies() } • Two or more classes • Validate interaction between classes • Still white box testing Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 14. ACCEPTANCE Scenario: Get presenters as JSON Given I have some speakers at the conference When I get "speakers" as JSON Then I should get a response with all the speakers • Black box testing • Manipulate the application • Populate the database with expected data • Validate using the application values Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 15. ONE SCENARIO PER TEST • Easy to approach • Easy to understand • Easy to maintain Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 16. EVERYTHING TOGETHER [TestFixture] public class MovieLibraryTest { [Test] public void When_Initialized_Should_Be_Empty() [Test] public void When_Adding_Should_Appear_In_The_Contents() [Test] public void When_Adding_Should_Trigger_Event() [Test] public void When_ListingNV_Should_Ask_Critic() [Test] public void When_ListingNV_Should_Return_All_NV() [Test] public void When_ListingNV_Should_Throw_Exception_If_Missing_Critic() } Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 17. SCENARIO IDENTIFICATION 1.Initialize 3.Listing NV movies 1.1.Library should be empty 3.1.Missing Critic 2.Addingd Movies 3.2.Listing only NV 2.1.Contents are changes 2.2.Event is triggered Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 18. ADDING MOVIES public class When_movie_library_adds_a_movie { public void Should_include_the_movie() public void Should_notify_an_element_was_added() } Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 19. LISTING NV MOVIES public class When_movie_library_list_nv_with_no_critic { public void Should_throw_missing_critic_exception() } public class When_movie_library_lists_nv_movies { public void Should_return_all_the_nv_movies() } Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 20. WHO’S YOUR DD? • Quality Driver • Use the methodology • Gain confidence • Don’t show off Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 21. THE TEST public class When_creating_cells { public void Should_not_be_alive() { var cell = new Cell(); cell.Alive.Should().Be.False(); } } Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 22. MAKE IT PASS • Minimum amount of code public class Cell { • Don’t think about what’s public bool Alive { next get { return xxxx? } } • One bit of code at a time } • Let the technology drive • Now, make it fail! Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 23. BEHAVIOUR VERIFICATION • Test setters and getters • Verify the dependencies called • Test private members • How do I know when’s enough? Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 24. TESTING THE CALL public class When_movie_library_lists_nv_movies { public void Should_return_all_the_nv_movies() public void Should_call_the_critic_3_times() } Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 25. SPECIFY BEHAVIOUR • Avoid testing implementation • Setup all the behaviour • Find the scenario that fails • Test calls if can’t be verified otherwise Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 26. LACK OF AUTOMATION • Who runs the test? • Who’s in charge of deployment? • Who enforces policies on commit? • Where’s the documentation? • Do I need the IDE in order to build? Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 27. ITERATION 0 • Run all the tests since day one • Commit should trigger build • Build should trigger test • Test may trigger deploy • Scripts should run locally Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 28. LEGACY CODE • The code is a mess • Can’t refactor easily • No documentation • No testing • Who dares to make a change? Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 29. WHAT TO DO? • Acceptance tests to document current features • Migrations to capture current database • Migrations to capture changes and population • Unit test works better for new modifications Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 30. DEPENDENCIES • Hardcoded dependencies • Unit or integration test? • Isolation Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 31. SOMETHING SMELLS public class MovieLibrary { private TwitterNotifier _notifier; public MovieLibrary() { this._notifier = new TwitterNotifier(); } } Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 32. EXTRACT DEPENDENCIES public class MovieLibrary { private INotifier _notifier; public MovieLibrary(INotifier notifier) { this._notifier = notifier; } } • Introduces dependency in the constructor / setter • Easy to test and maintain Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 33. RANDOM VALUES • Are u kidding? • How do I know are the right values? • How do I know is not going to fail the next one? Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 34. TEST WITH PARAMETERS [Row(1)] • Avoid duplication and [Row(2)] repetition void Method(int arg) [Row(typeof(...))] • Generic Parameters void Method<T>(...) • Parameters Factories [Factory(...)] void Method(string arg) • Random strings void Method([Random]...) • Random numbers void Method([Random]..., [Factory]...) Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 35. QUESTIONS? Amir Barylko - Common mistakes and pitfalls MavenThought Inc.
  • 36. RESOURCES • Contact me: amir@barylko.com, @abarylko • Download: http://www.orhtocoders.com/presentations • Books: The rSpec book, xUnit Patterns. Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.
  • 37. RESOURCES II • NUnit: http://www.nunit.org • Gallio & MbUnit: http://www.gallio.org • MavenThought Testing: http://maventcommons.codeplex.com • Rhino Mocks: http://www.ayende.com • StructureMap: http://structuremap.sourcefore.com • TeamCity: http://www.jetbrains.com Amir Barylko - TDD Mistakes & Pitfalls MavenThought Inc.