SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
AMIR BARYLKO
                                    TDD
                                   INTRO



                            ONLINE BUSINESS SYSTEMS
                                    APRIL 2011

Amir Barylko - OBS Apr ‘11                            MavenThought Inc.
Wednesday, April 27, 2011
WHO AM I?

    • Quality               Expert

    • Architect

    • Developer

    • Mentor

    • Great             cook

    • The           one who’s entertaining you for the next hour!
Amir Barylko - OBS Apr ‘11                                          MavenThought Inc.
Wednesday, April 27, 2011
RESOURCES

    • Email: amir@barylko.com

    • Twitter: @abarylko

    • Blog: http://www.orthocoders.com

    • Materials: http://www.orthocoders.com/presentations




Amir Barylko - OBS Apr ‘11                              MavenThought Inc.
Wednesday, April 27, 2011
TDD TRAINING

    • When: May             26 & 27

    • More             info: http://www.maventhought.com

    • Goal: Learn TDD          with real hands on examples




Amir Barylko - OBS Apr ‘11                                   MavenThought Inc.
Wednesday, April 27, 2011
INTRO
                             Why projects fail?
                              Reality Check
                             No more excuses
                               Why TDD?



Amir Barylko - OBS Apr ‘11                        MavenThought Inc.
Wednesday, April 27, 2011
WHY PROJECTS FAIL?

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


Amir Barylko - OBS Apr ‘11                           MavenThought Inc.
Wednesday, April 27, 2011
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 - OBS Apr ‘11                        MavenThought Inc.
Wednesday, April 27, 2011
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 - OBS Apr ‘11                                MavenThought Inc.
Wednesday, April 27, 2011
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 - OBS Apr ‘11                                       MavenThought Inc.
Wednesday, April 27, 2011
APPLYING TDD
                                  Iteration 0 .. N
                                Quality as a Driver
                              Red - Green - Refactor




Amir Barylko - OBS Apr ‘11                             MavenThought Inc.
Wednesday, April 27, 2011
ITERATION 0

    • Flush           out architecture.

    • Setup Testing            harness for TDD and BDD.

    • Setup             continuous integration.

    • Setup             scripts to build, deploy, etc.

    • Setup             visual communication tools.


Amir Barylko - OBS Apr ‘11                                MavenThought Inc.
Wednesday, April 27, 2011
ITERATION 1.. N
    • Start           by Story Planning

         • Pair         programming (switching often)   Every day!

         • Daily            Scrum

    • End          with Retrospective




Amir Barylko - OBS Apr ‘11                                      MavenThought Inc.
Wednesday, April 27, 2011
QUALITY AS A DRIVER
                                           Red
                                           BDD

                                           Red




        Refactor                Refactor   TDD   Green   Green




Amir Barylko - OBS Apr ‘11                                 MavenThought Inc.
Wednesday, April 27, 2011
RED

    •Write                  a test that fails
    •Relax, is                ok if it compiles




Amir Barylko - OBS Apr ‘11                        MavenThought Inc.
Wednesday, April 27, 2011
GREEN

    • Try            to make the test pass
    • Do             a simple solution
    • Use              default values (not throwing exceptions)
    • Don’t                 worry if the code “smells”


Amir Barylko - OBS Apr ‘11                                 MavenThought Inc.
Wednesday, April 27, 2011
REFACTOR

    • Avoid                 repeating code
    • Avoid                 hardcoding dependencies
    • Avoid “write                only” code
    • Refactor                with confidence!
    • Run              all tests if possible
Amir Barylko - OBS Apr ‘11                            MavenThought Inc.
Wednesday, April 27, 2011
DEMO
                             Unit Testing Frameworks
                              Given - When - Then
                                 Listing Contents
                                      Reviews



Amir Barylko - OBS Apr ‘11                             MavenThought Inc.
Wednesday, April 27, 2011
TESTING FRAMEWORKS

    • MsTest, xUnit, nUnit, MbUnit, MSpec

    • Similar “hooks”

         • Before           and after test

         • Before           and after all test

         • Arrange, Act, Assert



Amir Barylko - OBS Apr ‘11                       MavenThought Inc.
Wednesday, April 27, 2011
GIVEN WHEN THEN

    • Test          one “scenario” at a time

    • Clear            identification of functionality

    • Easy           to write, understand and maintain

    • Repeatable, easy            to learn	





Amir Barylko - OBS Apr ‘11                               MavenThought Inc.
Wednesday, April 27, 2011
LISTING CONTENTS

    • Controller “Movies” method “Index”

    • Two            scenarios

         • Given            I have no movies....

         • Given            I have the following movies....

    • Where                 do I get the movies from?


Amir Barylko - OBS Apr ‘11                                    MavenThought Inc.
Wednesday, April 27, 2011
GIVEN I HAVE NO MOVIES
    [It]
    public void Should_not_return_any_movies()
    {
         var result = (ViewResult)this.ActualResult;

             var actual = (IEnumerable<IMovie>) result.ViewData.Model;

             actual.Should().Be.Empty();
    }

    [It]
    public void Should_render_the_index_view()
    {
         this.ActualResult.AssertViewRendered();
    }


Amir Barylko - OBS Apr ‘11                                               MavenThought Inc.
Wednesday, April 27, 2011
GIVEN I HAVE 10 MOVIES
    [It]
    public void Should_return_all_the_movies()
    {
         var result = (ViewResult)this.ActualResult;

              var actual = (IEnumerable<IMovie>) result.ViewData.Model;

              actual.Should().Have.SameValuesAs(this._movies);
    }




Amir Barylko - OBS Apr ‘11                                        MavenThought Inc.
Wednesday, April 27, 2011
ARE WE DONE?

    • Fail            1: IMovieLibrary is not registered in the container

    • Fail            2: SimpleMovieLibrary needs the db name

    • How             can we make sure it works?

    • Is TDD                enough?




Amir Barylko - OBS Apr ‘11                                            MavenThought Inc.
Wednesday, April 27, 2011
FIX THE CONTAINER

    Component
      .For<IMovieLibrary>()
      .Instance(new SimpleMovieLibrary(dbFile))...




Amir Barylko - OBS Apr ‘11                      MavenThought Inc.
Wednesday, April 27, 2011
SAFETY NET
    Scenario: Browse available movies
         Given I have the following movies:
              | title             |
              | Blazing Saddles |
              | Space Balls       |
         When I go to "Movies"
         Then I should see in the listing:
              | title                 |
              | Blazing Saddles       |
              | Space Balls           |




Amir Barylko - OBS Apr ‘11                    MavenThought Inc.
Wednesday, April 27, 2011
SUMMARY
                               Benefits
                              Challenges
                              Adoption




Amir Barylko - OBS Apr ‘11                 MavenThought Inc.
Wednesday, April 27, 2011
BENEFITS

    • Let           the methodology drive
    • It      will save your bacon!
    • High                  quality the whole way!
    • Very                  few bugs!
    • Do             your duty as developer!
Amir Barylko - OBS Apr ‘11                           MavenThought Inc.
Wednesday, April 27, 2011
CHALLENGES

    • Very             different from conventional testing
    • Many                  developers find it complex to learn at first
    • Hard              to start without a Mentor
    • Management                   buy in
    • Difficult                to keep under deadline pressure
    • Beware                  of code coverage!
Amir Barylko - OBS Apr ‘11                                           MavenThought Inc.
Wednesday, April 27, 2011
ADOPTION

    • Find           Mentor/Couch/Trainer
    • Small             iterations
    • Have              metrics ready (velocity, etc)
    • Do           whatever works for you
    • Find           out which tools will benefit you
    • Automate,                  automate, automate!
Amir Barylko - OBS Apr ‘11                              MavenThought Inc.
Wednesday, April 27, 2011
QUESTIONS?




Amir Barylko - .NET UG Mar ‘11                MavenThought Inc.
Wednesday, April 27, 2011
RESOURCES

    • Email: amir@barylko.com

    • Twitter: @abarylko

    • Slides: http://www.orthocoders.com/presentations




Amir Barylko - OBS Apr ‘11                               MavenThought Inc.
Wednesday, April 27, 2011
RESOURCES II




Amir Barylko - OBS Apr ‘11                  MavenThought Inc.
Wednesday, April 27, 2011
TDD TRAINING

    • When: May             26 & 27

    • More             info: http://www.maventhought.com

    • Goal: Learn TDD          with real hands on examples




Amir Barylko - OBS Apr ‘11                                   MavenThought Inc.
Wednesday, April 27, 2011

Contenu connexe

En vedette

Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Agileee
 

En vedette (9)

TDD Boot Camp Sapporo 1.5
TDD Boot Camp Sapporo 1.5 TDD Boot Camp Sapporo 1.5
TDD Boot Camp Sapporo 1.5
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
TDD for the Newb Who Wants to Become an Apprentice
TDD for the Newb Who Wants to Become an ApprenticeTDD for the Newb Who Wants to Become an Apprentice
TDD for the Newb Who Wants to Become an Apprentice
 
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz BankowskiPitfalls Of Tdd Adoption by Bartosz Bankowski
Pitfalls Of Tdd Adoption by Bartosz Bankowski
 
No estimates
No estimatesNo estimates
No estimates
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep dive
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 

Similaire à obs-tdd-intro

Codemash-iron-ruby-match-made-in-heaven
Codemash-iron-ruby-match-made-in-heavenCodemash-iron-ruby-match-made-in-heaven
Codemash-iron-ruby-match-made-in-heaven
Amir Barylko
 
Quality web-acceptance
Quality web-acceptanceQuality web-acceptance
Quality web-acceptance
Amir Barylko
 
Continuous Deployment at Disqus (Pylons Minicon)
Continuous Deployment at Disqus (Pylons Minicon)Continuous Deployment at Disqus (Pylons Minicon)
Continuous Deployment at Disqus (Pylons Minicon)
zeeg
 
MDW Boulder April '11 | Tim Malbon_How to actually make something
MDW Boulder April '11 | Tim Malbon_How to actually make somethingMDW Boulder April '11 | Tim Malbon_How to actually make something
MDW Boulder April '11 | Tim Malbon_How to actually make something
Boulder Digital Works at CU
 
Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011) Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011)
Leonardo Borges
 
Devopsdays Goteborg 2011 - State of the Union
Devopsdays Goteborg 2011 - State of the UnionDevopsdays Goteborg 2011 - State of the Union
Devopsdays Goteborg 2011 - State of the Union
John Willis
 

Similaire à obs-tdd-intro (20)

agile-planning
agile-planningagile-planning
agile-planning
 
Codemash-iron-ruby-match-made-in-heaven
Codemash-iron-ruby-match-made-in-heavenCodemash-iron-ruby-match-made-in-heaven
Codemash-iron-ruby-match-made-in-heaven
 
Quality web-acceptance
Quality web-acceptanceQuality web-acceptance
Quality web-acceptance
 
Iterations-zero-n
Iterations-zero-nIterations-zero-n
Iterations-zero-n
 
Is Advanced Verification for FPGA based Logic needed
Is Advanced Verification for FPGA based Logic neededIs Advanced Verification for FPGA based Logic needed
Is Advanced Verification for FPGA based Logic needed
 
High quality iOS development
High quality iOS developmentHigh quality iOS development
High quality iOS development
 
Atlassian RoadTrip 2011 Slide Deck
Atlassian RoadTrip 2011 Slide DeckAtlassian RoadTrip 2011 Slide Deck
Atlassian RoadTrip 2011 Slide Deck
 
Continuous Deployment at Disqus (Pylons Minicon)
Continuous Deployment at Disqus (Pylons Minicon)Continuous Deployment at Disqus (Pylons Minicon)
Continuous Deployment at Disqus (Pylons Minicon)
 
Mozilla: Continuous Deploment on SUMO
Mozilla: Continuous Deploment on SUMOMozilla: Continuous Deploment on SUMO
Mozilla: Continuous Deploment on SUMO
 
MDW Boulder April '11 | Tim Malbon_How to actually make something
MDW Boulder April '11 | Tim Malbon_How to actually make somethingMDW Boulder April '11 | Tim Malbon_How to actually make something
MDW Boulder April '11 | Tim Malbon_How to actually make something
 
Godoggo
GodoggoGodoggo
Godoggo
 
David Mytton, Boxed Ice
David Mytton, Boxed Ice   David Mytton, Boxed Ice
David Mytton, Boxed Ice
 
why-tdd
why-tddwhy-tdd
why-tdd
 
PRDC11-Jruby-ironruby
PRDC11-Jruby-ironrubyPRDC11-Jruby-ironruby
PRDC11-Jruby-ironruby
 
Bonfire... How'd You Do That?! - AtlasCamp 2011
Bonfire... How'd You Do That?! - AtlasCamp 2011Bonfire... How'd You Do That?! - AtlasCamp 2011
Bonfire... How'd You Do That?! - AtlasCamp 2011
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackability
 
Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011) Clouds against the Floods (RubyConfBR2011)
Clouds against the Floods (RubyConfBR2011)
 
ExpOn 2011 - Diego Monteiro - Níveis de Maturidade nas Mídias Sociais
ExpOn 2011 - Diego Monteiro - Níveis de Maturidade nas Mídias SociaisExpOn 2011 - Diego Monteiro - Níveis de Maturidade nas Mídias Sociais
ExpOn 2011 - Diego Monteiro - Níveis de Maturidade nas Mídias Sociais
 
Journey to 1000 tests a day
Journey to 1000 tests a dayJourney to 1000 tests a day
Journey to 1000 tests a day
 
Devopsdays Goteborg 2011 - State of the Union
Devopsdays Goteborg 2011 - State of the UnionDevopsdays Goteborg 2011 - State of the Union
Devopsdays Goteborg 2011 - State of the Union
 

Plus de Amir Barylko

Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
Amir 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; Coffeescript
Amir Barylko
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
Amir Barylko
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
Amir Barylko
 

Plus de Amir Barylko (20)

Functional converter project
Functional converter projectFunctional converter project
Functional converter project
 
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
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
SDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescriptSDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescript
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
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
vu2urc
 

Dernier (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 

obs-tdd-intro

  • 1. AMIR BARYLKO TDD INTRO ONLINE BUSINESS SYSTEMS APRIL 2011 Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 2. WHO AM I? • Quality Expert • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour! Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 3. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Blog: http://www.orthocoders.com • Materials: http://www.orthocoders.com/presentations Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 4. TDD TRAINING • When: May 26 & 27 • More info: http://www.maventhought.com • Goal: Learn TDD with real hands on examples Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 5. INTRO Why projects fail? Reality Check No more excuses Why TDD? Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 6. WHY PROJECTS FAIL? • Delivering late or over budget • Delivering the wrong thing • Unstable in production • Costly to maintain Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 7. 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 - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 8. 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 - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 9. 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 - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 10. APPLYING TDD Iteration 0 .. N Quality as a Driver Red - Green - Refactor Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 11. ITERATION 0 • Flush out architecture. • Setup Testing harness for TDD and BDD. • Setup continuous integration. • Setup scripts to build, deploy, etc. • Setup visual communication tools. Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 12. ITERATION 1.. N • Start by Story Planning • Pair programming (switching often) Every day! • Daily Scrum • End with Retrospective Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 13. QUALITY AS A DRIVER Red BDD Red Refactor Refactor TDD Green Green Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 14. RED •Write a test that fails •Relax, is ok if it compiles Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 15. GREEN • Try to make the test pass • Do a simple solution • Use default values (not throwing exceptions) • Don’t worry if the code “smells” Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 16. REFACTOR • Avoid repeating code • Avoid hardcoding dependencies • Avoid “write only” code • Refactor with confidence! • Run all tests if possible Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 17. DEMO Unit Testing Frameworks Given - When - Then Listing Contents Reviews Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 18. TESTING FRAMEWORKS • MsTest, xUnit, nUnit, MbUnit, MSpec • Similar “hooks” • Before and after test • Before and after all test • Arrange, Act, Assert Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 19. GIVEN WHEN THEN • Test one “scenario” at a time • Clear identification of functionality • Easy to write, understand and maintain • Repeatable, easy to learn Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 20. LISTING CONTENTS • Controller “Movies” method “Index” • Two scenarios • Given I have no movies.... • Given I have the following movies.... • Where do I get the movies from? Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 21. GIVEN I HAVE NO MOVIES [It] public void Should_not_return_any_movies() { var result = (ViewResult)this.ActualResult; var actual = (IEnumerable<IMovie>) result.ViewData.Model; actual.Should().Be.Empty(); } [It] public void Should_render_the_index_view() { this.ActualResult.AssertViewRendered(); } Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 22. GIVEN I HAVE 10 MOVIES [It] public void Should_return_all_the_movies() { var result = (ViewResult)this.ActualResult; var actual = (IEnumerable<IMovie>) result.ViewData.Model; actual.Should().Have.SameValuesAs(this._movies); } Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 23. ARE WE DONE? • Fail 1: IMovieLibrary is not registered in the container • Fail 2: SimpleMovieLibrary needs the db name • How can we make sure it works? • Is TDD enough? Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 24. FIX THE CONTAINER Component .For<IMovieLibrary>() .Instance(new SimpleMovieLibrary(dbFile))... Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 25. SAFETY NET Scenario: Browse available movies Given I have the following movies: | title | | Blazing Saddles | | Space Balls | When I go to "Movies" Then I should see in the listing: | title | | Blazing Saddles | | Space Balls | Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 26. SUMMARY Benefits Challenges Adoption Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 27. BENEFITS • Let the methodology drive • It will save your bacon! • High quality the whole way! • Very few bugs! • Do your duty as developer! Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 28. CHALLENGES • Very different from conventional testing • Many developers find it complex to learn at first • Hard to start without a Mentor • Management buy in • Difficult to keep under deadline pressure • Beware of code coverage! Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 29. ADOPTION • Find Mentor/Couch/Trainer • Small iterations • Have metrics ready (velocity, etc) • Do whatever works for you • Find out which tools will benefit you • Automate, automate, automate! Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 30. QUESTIONS? Amir Barylko - .NET UG Mar ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 31. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Slides: http://www.orthocoders.com/presentations Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 32. RESOURCES II Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011
  • 33. TDD TRAINING • When: May 26 & 27 • More info: http://www.maventhought.com • Goal: Learn TDD with real hands on examples Amir Barylko - OBS Apr ‘11 MavenThought Inc. Wednesday, April 27, 2011