AMIR BARYLKO                                    TDD                                   INTRO                            ONL...
WHO AM I?    • Quality               Expert    • Architect    • Developer    • Mentor    • Great             cook    • The...
RESOURCES    • Email: amir@barylko.com    • Twitter: @abarylko    • Blog: http://www.orthocoders.com    • Materials: http:...
TDD TRAINING    • When: May             26 & 27    • More             info: http://www.maventhought.com    • Goal: Learn T...
INTRO                             Why projects fail?                              Reality Check                           ...
WHY PROJECTS FAIL?    • Delivering               late or over budget    • Delivering               the wrong thing    • Un...
REALITY CHECK    • It  is impossible to gather all the requirements at        the beginning of a project.    • Whatever   ...
NO MORE EXCUSES    • It     works on my computer!   • We need a satellite                                      connection ...
WHY TDD?    • Prove                 that your code     • Regression   tests as        works                               ...
APPLYING TDD                                  Iteration 0 .. N                                Quality as a Driver         ...
ITERATION 0    • Flush           out architecture.    • Setup Testing            harness for TDD and BDD.    • Setup      ...
ITERATION 1.. N    • Start           by Story Planning         • Pair         programming (switching often)   Every day!  ...
QUALITY AS A DRIVER                                           Red                                           BDD           ...
RED    •Write                  a test that fails    •Relax, is                ok if it compilesAmir Barylko - OBS Apr ‘11 ...
GREEN    • Try            to make the test pass    • Do             a simple solution    • Use              default values...
REFACTOR    • Avoid                 repeating code    • Avoid                 hardcoding dependencies    • Avoid “write   ...
DEMO                             Unit Testing Frameworks                              Given - When - Then                 ...
TESTING FRAMEWORKS    • MsTest, xUnit, nUnit, MbUnit, MSpec    • Similar “hooks”         • Before           and after test...
GIVEN WHEN THEN    • Test          one “scenario” at a time    • Clear            identification of functionality    • Easy...
LISTING CONTENTS    • Controller “Movies” method “Index”    • Two            scenarios         • Given            I have n...
GIVEN I HAVE NO MOVIES    [It]    public void Should_not_return_any_movies()    {         var result = (ViewResult)this.Ac...
GIVEN I HAVE 10 MOVIES    [It]    public void Should_return_all_the_movies()    {         var result = (ViewResult)this.Ac...
ARE WE DONE?    • Fail            1: IMovieLibrary is not registered in the container    • Fail            2: SimpleMovieL...
FIX THE CONTAINER    Component      .For<IMovieLibrary>()      .Instance(new SimpleMovieLibrary(dbFile))...Amir Barylko - ...
SAFETY NET    Scenario: Browse available movies         Given I have the following movies:              | title           ...
SUMMARY                               Benefits                              Challenges                              Adoptio...
BENEFITS    • Let           the methodology drive    • It      will save your bacon!    • High                  quality th...
CHALLENGES    • Very             different from conventional testing    • Many                  developers find it complex ...
ADOPTION    • Find           Mentor/Couch/Trainer    • Small             iterations    • Have              metrics ready (...
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/presentationsAmir B...
RESOURCES IIAmir Barylko - OBS Apr ‘11                  MavenThought Inc.Wednesday, April 27, 2011
TDD TRAINING    • When: May             26 & 27    • More             info: http://www.maventhought.com    • Goal: Learn T...
Upcoming SlideShare
Loading in...5
×

obs-tdd-intro

346

Published on

PResentation done at

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
346
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

obs-tdd-intro

  1. 1. AMIR BARYLKO TDD INTRO ONLINE BUSINESS SYSTEMS APRIL 2011Amir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  2. 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. 3. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Blog: http://www.orthocoders.com • Materials: http://www.orthocoders.com/presentationsAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  4. 4. TDD TRAINING • When: May 26 & 27 • More info: http://www.maventhought.com • Goal: Learn TDD with real hands on examplesAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  5. 5. INTRO Why projects fail? Reality Check No more excuses Why TDD?Amir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  6. 6. WHY PROJECTS FAIL? • Delivering late or over budget • Delivering the wrong thing • Unstable in production • Costly to maintainAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  7. 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. 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. 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 designAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  10. 10. APPLYING TDD Iteration 0 .. N Quality as a Driver Red - Green - RefactorAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  11. 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. 12. ITERATION 1.. N • Start by Story Planning • Pair programming (switching often) Every day! • Daily Scrum • End with RetrospectiveAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  13. 13. QUALITY AS A DRIVER Red BDD Red Refactor Refactor TDD Green GreenAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  14. 14. RED •Write a test that fails •Relax, is ok if it compilesAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  15. 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. 16. REFACTOR • Avoid repeating code • Avoid hardcoding dependencies • Avoid “write only” code • Refactor with confidence! • Run all tests if possibleAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  17. 17. DEMO Unit Testing Frameworks Given - When - Then Listing Contents ReviewsAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  18. 18. TESTING FRAMEWORKS • MsTest, xUnit, nUnit, MbUnit, MSpec • Similar “hooks” • Before and after test • Before and after all test • Arrange, Act, AssertAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  19. 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. 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. 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. 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. 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. 24. FIX THE CONTAINER Component .For<IMovieLibrary>() .Instance(new SimpleMovieLibrary(dbFile))...Amir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  25. 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. 26. SUMMARY Benefits Challenges AdoptionAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  27. 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. 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. 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. 30. QUESTIONS?Amir Barylko - .NET UG Mar ‘11 MavenThought Inc.Wednesday, April 27, 2011
  31. 31. RESOURCES • Email: amir@barylko.com • Twitter: @abarylko • Slides: http://www.orthocoders.com/presentationsAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  32. 32. RESOURCES IIAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  33. 33. TDD TRAINING • When: May 26 & 27 • More info: http://www.maventhought.com • Goal: Learn TDD with real hands on examplesAmir Barylko - OBS Apr ‘11 MavenThought Inc.Wednesday, April 27, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×