avatars of tdd

Click here to load reader

Post on 06-May-2015

10.258 views

Category:

Technology

4 download

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 [email protected] 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 [email protected] 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("[email protected]", "[email protected]"); }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 exceptions com.vis.billing.fixtures.PaidCashBillprocedure details on the billaccount details name costaccount number patient name owner name Routine Office Visit 2501001 FluffyDave Atkins Rabies Vaccination 50procedure details payCash name cost patient name? owner name? account number? bill no? payment method? amount paid? Routine Office Visit 250 Fluffy Dave Atkins 10011Cash 300 Rabies Vaccination 50 bill check paid true account number? owner name? patient name? total? paid? 1001 Dave Atkins Fluffy300 falsecheck total 0 Licensed Under Creative Commons by Naresh JainFriday, September 18, 200916 37. Outside In: ATDD Output Licensed Under Creative Commons by Naresh JainFriday, September 18, 2009 17 38. ATDD: Another ExampleAcceptance test:class FluffyTest < Test::Unit::TestCasedef test_examination_and_shotsvet = Veterinarian.newclinic = Clinic.new "Main Line health"dave = Owner.new "Dave"fluffy = Patient.new "Fluffy"dave.has fluffyvisit = clinic.visit(fluffy, vet) do |v|v.procedure "Rabies vaccination", 50end invoice = visit.invoiceassert_equal invoice.to_s,