Avatars Of TDD

  • View
    10.169

  • Download
    3

Embed Size (px)

DESCRIPTION

Presentation on Avatars of TDD and some concepts you need to know before you take a jump to TDD.

Transcript

  • 1.Avatars of TDD Rule of DiversityDistrust all claims for One True WayLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20091

2. Overview TDD Rhythm - Test, Code, RefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 20092 3. OverviewAdd a TestTDD Rhythm - Test, Code, RefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 4. OverviewAdd a Test Run the TestTDD Rhythm - Test, Code, RefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 20092 5. Overview Add a Test Pass Run the TestTDD Rhythm - Test, Code, RefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 6. Overview Add a Test Pass Run the Test FailTDD Rhythm - Test, Code, RefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 7. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little changeLicensed Under Creative Commons by Naresh JainFriday, September 18, 20092 8. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little change Run the TestLicensed Under Creative Commons by Naresh JainFriday, September 18, 20092 9. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little changeFail Run the TestLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 10. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little changeFail Run the TestPassLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 11. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little changeFail Run the TestPassRefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 12. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little changeFail Run the TestPassRefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 13. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little changeFail Run the TestPassRefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 14. Overview Add a Test Pass Run the TestFailTDD Rhythm - Test, Code, Refactor Make a little changeFail Run the TestPassRefactorLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 2 15. Simple easy to understand, deal with, use, etc.: a simple matter; simple tools.not elaborate or articial; plain: a simple style.not ornate or luxurious; unadorned: a simple gown.unaffected; unassuming; modest: a simple manner.not complicated: a simple design.not complex or compound; single.occurring or considered alone; mere; bare: the simple truth; a simple fact.free of deceit or guile; sincere; unconditional: a frank, simple answer.common or ordinary: a simple soldier.not grand or sophisticated; unpretentious: a simple way of life.humble or lowly: simple folk.inconsequential or rudimentary.Licensed Under Creative Commons by Naresh Jain Friday, September 18, 20093 16. What is Simple Design?A design that allows you to keep moving forward with least amount of resistanceLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20094 17. Embrace Simple DesignLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20095 18. Embrace Simple DesignLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20095 19. Embrace Simple DesignLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20095 20. Simple Design? easy to understand, deal with: communicates its intent. not elaborate or articial; plain: crisp and concise not ornate or luxurious; unadorned: minimalistic; least possible components (classes and methods). unaffected; unassuming; modest: does not have unanticipated side-effects. not complicated: avoids unnecessary conditional logic. not complex or compound; single: just does one thing and does it well. occurring or considered alone; mere; bare: to the point.Licensed Under Creative Commons by Naresh Jain Friday, September 18, 20096 21. Simple Design? ... free of deceit or guile; sincere; unconditional: abstracts implementation from intent, but does not deceive someone by concealing or misrepresenting the actual concept. common or ordinary: built on standard patterns which are well understood. not grand or sophisticated; unpretentious: fullls todays needs without unnecessary bells and whistles (over-engineering). humble or lowly. inconsequential or rudimentary: does not draw your attention to unnecessary details; achieves good abstractionsLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20097 22. Summary Do the Simplest thing that could possibly work YAGNI Design Patterns. Code Smells (Code Screams) Unix Programming Philosophy OO Design principles - SOLID, DRY, TDA Functional Programming - Immutability and Side effect free Simple Design and TDD go hand in handLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20098 23. Why bother about TDD? Condent & Feedback Design & Code minimalistic and clean Decoupling and Testable Safety net of executable, living, up-to-date specication Learning by listening to your code Slow down and think Communicate my design choices Efcient: Debugging and Manual Testing Maintain focus Reduce Wastage: Hand-oversLicensed Under Creative Commons by Naresh Jain Friday, September 18, 20099 24. Before you take the plunge...Licensed Under Creative Commons by Naresh Jain Friday, September 18, 200910 25. Before you take the plunge... System MetaphorElection MetaphorGoogle Search Engine MetaphorLicensed Under Creative Commons by Naresh Jain Friday, September 18, 200910 26. Before you take the plunge... System MetaphorElection MetaphorGoogle Search Engine Metaphor Thin SliceProTest - Dependency VoterProle Picture Licensed Under Creative Commons by Naresh Jain Friday, September 18, 2009 10 27. Before you take the plunge... System MetaphorElection MetaphorGoogle Search Engine Metaphor Thin SliceProTest - Dependency VoterProle Picture Interaction Design Licensed Under Creative Commons by Naresh Jain Friday, September 18, 2009 10 28. Before you take the plunge... System MetaphorElection MetaphorGoogle Search Engine Metaphor Thin SliceProTest - Dependency VoterProle Picture Interaction Design Tracer Bullets: Prototyping, a forgotten Design Practice Licensed Under Creative Commons by Naresh Jain Friday, September 18, 2009 10 29. Before you take the plunge...Micro-Design v/s Macro-Design v/s BUFD Unit Tests Validates Micro-Design There is No Spoon Fluent Interfaces in Test Behavior (verbs) as Test Class NamesLicensed Under Creative Commons by Naresh Jain Friday, September 18, 200911 30. There is no Spoon Veterinarian Information System (system responsible for billing & patient history) ChargeAccountForServices with the following test methods:makePaymentsAgainstAnAccount()completePaymentsResultInZeroAmountDueOnReceipt()incompletePaymentsDisplaysDueAmountOnTheReceipt()Another test class: GenerateBillsForClientAccount withnotifyIfAccountIsNotDueForPayment()billContainsTotalCostOfAllServicesTaken()And another test class: ManageClientVisits withtrackAllServicesTakenByThePatient()skipVisitIfPatientDidNotTakeAnyService()Licensed Under Creative Commons by Naresh Jain Friday, September 18, 2009 12 31. Other Test Naming Convention Others Naming ConventionMy Naming Convention itShouldSetAccountToLoggedInWhenPasswordMatchesmatchingPasswordLogsYouInitShouldSetAccountToRevokedAfterThreeFailedLoginAttempts threeFailedLoginAttemptsRevokesYourAccount itShouldNotSetAccountLoggedInIfPasswordDoesNotMatch nonMatchingPasswordDoesNotLogYouIn itShouldNotRevokeSecondAccountAfterTwoFailedAttemptsFirst failedLoginAttemptsOnOtherAccountsDoesNotImpactAccount MyAccountitShouldNowAllowConcurrentLogins sameUserCannotLoginConcurrently itShouldThrowExceptionIfAccountNotFoundonlyUserWithExistingAccountCanLogin ItShouldNotBePossibleToLogIntoRevokedAccount userWithRevokedAccountCannotLoginitShouldResetBackToInitialStateAfterSuccessfulLoginsuccessfulLoginResetsFailedAttemptCount Licensed Under Creative Commons by Naresh Jain Friday, September 18, 200913 32. Fluent InterfacesLicensed Under Creative Commons by Naresh Jain Friday, September 18, 200914 33. Fluent Interfaces@Testpublic void redirectDomainsWithSubDomainsPermanently() {server.redirect(google.com).withSubDomain().to(directi.com);client_requests(blog.google.com);response = domainForwardingServer.process(request);assertStatusIs(PermanentRedirect); assertLocationIs(directi.com/blog); assertStandardResponseHeaderIsPresent();}Licensed Under Creative Commons by Naresh Jain Friday, September 18, 2009 14 34. Fluent Interfaces@Testpublic void redirectDomainsWithSubDomainsPermanently() {server.redirect(google.com).withSubDomain().to(directi.com);client_requests(blog.google.com);response = domainForwardingServer.process(request);assertStatusIs(PermanentRedirect); assertLocationIs(directi.com/blog); assertStandardResponseHeaderIsPresent();}User naresh_from_mumbai = new User("naresh", "jains", "mumbai", "india", "indian"); Context lets = new Context(userService, dns); IdentitySuggester suggester = new IdentitySuggester(userService, dns, randomNumberGenerator);@Test public void avoidCelebrityNamesInGeneratedIds() { lets.assume("naresh", "jain").isACelebrityName(); List generatedIds = suggester.generateIdsFor(naresh_from_mumbai); lets.assertThat(generatedIds).are("nares@jain.com", "naresh@india.com"); }Licensed Under Creative Commons by Naresh Jain Friday, September 18, 2009 14 35. Avatars of TDD Business Facing Drives Development Critique productInside OutOutside In Technology/Implementation Facing Brian Maricks Test CategorizationLicensed Under Creative Commons by Naresh JainFriday, September 18, 2009 15 36. Outside In: ATDDFitnesse Document:Assertions: 17 right, 0 wrong, 0 ignored, 0 exceptio