tdr & tdd - meetupfiles.meetup.com/1508927/tdr & tdd.pdftdr & tdd test -driven...

23
12/16/15 1 TDR & TDD Test-Driven{Requirements & Development} By Mike Rieser (email:[email protected]) ENGINEERING PRACTICES “People have told me that they see Scrum as the management approach to agile development and XP as the engineering practices that make it effective, both bonded together by complimentary practices and goals.” – Ken Schwaber

Upload: others

Post on 25-Apr-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

1

TDR&TDDTest-Driven{Requirements&Development}ByMikeRieser (email:[email protected])

ENGINEERING PRACTICES

“PeoplehavetoldmethattheyseeScrumasthemanagementapproachtoagiledevelopmentandXPastheengineeringpracticesthatmakeiteffective,bothbondedtogetherbycomplimentarypracticesandgoals.”

– KenSchwaber

Page 2: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

2

ScrumforProcess, ExtremeProgramming(XP)forPractices

“Accordingly,wheneverIhaveasituationinwhichsoftwareisbeingdeveloped,Scrumisbeingused,andtheengineeringpracticesaresubstandard,IalsocallforXPtobeimplemented.”

– KenSchwaber

#3

Scrum’s InfluenceonExtremeProgramming(XP)

From: Kent Beck To: Jeff Sutherland <jsutherland>

Reply: [email protected]

Date: Mon, 15 May 1995 18:01:15 -0400 (EDT)

Subj: HBR paper

_____________________________________________________Isthere agoodplace togetreprints ofthe SCRUM paper fromHBR? I'vewritten patterns for something verysimilar andIwanttomakesure Istealasmanyideas aspossible.

Kent

#4

Page 3: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

3

MATURINGPRACTICES

DiscussionTeamsnewtoScrumtypically startbyputtingeverythinginprogressandtreatingtheiterationlikeamini-waterfall.

Howhaveyouseenteamsmature inthewaytheyapproachandaccomplish theirwork?

Page 4: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

4

SkillMaturityModelsAgile teamsmatureintheir skillsandpractices:• DreyfusModel: Novice toExpert.• MartialArts: Shu-Ha-Ri.• Meilir Page-Jones: InnocenttoResearcher.

NoviceAgileTreat anIteration likeamini-waterfall. Allstories putin flight atonce.QAgetssqueezed atthe

endhaving totesteverything thenight before the demo.

Page 5: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

5

QAPlightTheTester isattheendoftheprocessandmayhavequestions.

?

?

AdvancedBeginnerTeamstarts completing stories earlier, butstill approaches eachstory inatraditional fashion.

Page 6: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

6

StevenCoveytip: “Beginwith theendinmind.”Let’sisolateaUser Storyandthinkaboutit.

“Beginwiththeendinmind.”WhatifwebeganwithQATesting?

Page 7: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

7

QATestsandRequirements atthestart.Thiswrapsalotofthingsaround.NoticewheretheBAandQA endup?

Separate outtheDevtasks.

Page 8: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

8

Isolateeacharea.

Rearrange theDevtasks. Codemovesearlier.

Page 9: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

9

We’llredirect theflow.

AnalysisfeedsTests.FromTestswegostraight toCode.

Page 10: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

10

Let’snameeachofthesekeyareas.

Test-DrivenRequirements +Test-DrivenDevelopment

Page 11: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

11

Mature teamwithmature practicesPracticingTest-DrivenRequirementswithTest-DrivenDevelopment

TEST-DRIVENREQUIREMENTS

“Anexamplewouldbehandyrightaboutnow.”– BrianMarick

Page 12: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

12

TestTablesarebestdonecollaboratively!

SoftwareRequirements asaTable“...anysoftwareprogramcanbethoughtofasatablethatmapsprograminputstotheircorrespondingcorrectoutputs.Thischaracterizationofprogrammingassumesafinitenumberoffiniteinputs,whichisfairforpracticalpurposes” 27

July 2001 issue of ACM Software Engineering Notes, J. P. Lewis

Page 13: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

13

WorldofWarcraftCharacterMovementCharacter MovementCharacterName

CharacterLocation

ObjectLocation Move Location? #Comment

Operandi (0, 0,0) - Forward (1,0,0) Unhinderedmovement

Operandi (0,0, 0) (-1, 0,0) Backward (0,0,0) Blockedmovement

Persona!

ATMWithdrawCashTestTableWithdraw Cash

ATM CashAccountBalance

RequestAmount Result?

ATMCash?

AccountBalance? #Comment

$1,000 $5,000 $100 OK $900 $4,900 Happy

$1,000 $1,000 $1,000 OK 0 0 Boundary

$100 $5,000 $200 ERROR $100 $5,000 InsufficientATMcash

$1,000 $100 $200 ERROR $1,000 $100 Insufficientacct balance

$1,000 -$100 $200 ERROR $1,000 -$135 Overdraftfee!

Page 14: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

14

Gherkin– Given-When-ThenGiven anAccountwitha$5,000balanceAnd theATMwith$1,000cash

When thePatronwithdraws$100cash

Then theAccountbalance is$4,900And theATMhas$900cash

CommonTools• Fit(orSlim)andFitNesse (JavaorC#)• SpecFlow (C#)• Jbehave (Java)• Cucumber (Ruby)• Concordian• Nominations?

Page 15: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

15

Discussion• AnyonehavestoriesofTest-DrivenRequirementssparkingcollaboration onteams?

• When’sthebesttimetohavetheteamcreatethetests?

TEST-DRIVENDEVELOPMENT

Page 16: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

16

SoftwareDevelopment ProcessDependencies

34

Waterfall

UpfrontRequirements

Upfront Design

Agile

Evolutionary Design

Refactoring

Automated DeveloperTests

TestFirst

TestAfter

Test-AfterApproach

TraditionalWay– TestAfter• 1daytothinkanddesign• 2daystowritethecode• Ohyeah,2daystowritetheunittests

DesignJ

CodeK

UnitTestL

35

Page 17: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

17

Test-FirstApproach

TDDWay– TestFirst• Takesaboutthesametimeasjustdesignandcodedidbefore• UnitTestsseemingly forfree– how?

Writeatest

KMakeitpass

JMakeitright

J

36

WhatisTDD?• DeveloperPractice• Test-FirstProgramming• IncrementalDesign• One testatatime• TDDdoesunittestingbutunittestingisnotnecessarilyTDD

Page 18: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

18

WhatTDDisNot!• Writing allthetests beforethecode• NotQATesting• Not IntegrationTesting

WhatisRed?Afailing testislikeahuntinglicense tochangeproductioncode.• Enhancements – addatesttoaddnewfunctionality.

• Defects – reproduce thebugasafailingtest.

Onlyintroduceasmuchofatestasyoucangettogreen insay,5mins.

Page 19: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

19

WhatisGreen?GettoGreenquickly!ObviousImplementation – ifyouknowwhattodo,justdoit!Fake It!– whenyoudon’tuseaconstant!

WhatisRefactor?• Workincrementally.• BeabletoshowGreen aftereachchange.• Removeduplication.• CleanasyouGo!

Page 20: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

20

Refactor– whatdoyoumean?if ( ... ) {

...i = i + 1;

} else {...i = i + 1;

}

if ( … ) {…

} else {…

}

i = i + 1;

if ( ... ) {...

} else {...

}

i = i + 1;

WhatisIntegrate??• Integrateasfrequentlyaspossible.• Maynotbecomplete,butifdone-enough,shareit.• (ItypicallyavoidcheckinginFakes.)

Page 21: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

21

Test-Firstvs Test-AfterTest-First

• Thetestsgetwritten.• Testablecodeisgenerallyflexiblecode.

• Lowercoupling• Highercohesion• AllowsRefactoring• Confidence

Test-After

• Sometimestheunittestsget“skipped.”

• Teststhatstartfromawizardaregenerallyprettypoor.

WhatAreUnitTests?• Testswhichhaveaspecific focuswhichcallamethod(orfunction).

• Verify thatthe requirements arebeingmetbythecodewhentestedinisolation.

• “Likeacompiler” forthebusiness requirements.

Page 22: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

22

WhatUnitTestsareNOT!

BenefitsofTDD?• Testfirstismorefunthattestafter• UnitTestsactuallygetwritten• Producestestabledesigns• Thinkoutside-in, firstabouthowtouse,thenabouthowtodoit• GoodunitteststhatsupportRefactoring• RequirementsClarification&Understanding• Confidence (nofear)• Solutions thatfitlikeahandinaglove• Version1.0codethatyouarehappywith• ReducesDefects

Page 23: TDR & TDD - Meetupfiles.meetup.com/1508927/TDR & TDD.pdfTDR & TDD Test -Driven {Requirements & Development} By Mike Rieser(email:mike@mrieser.com) ENGINEERING PRACTICES “People have

12/16/15

23

TDD– “Rediscovered”byKentBeck“TotheunknownauthorofthebookwhichIreadasaweird12-yearoldthatsuggestedyoutypeintheexpectedoutputtapefromarealinputtape,thencodeuntiltheactualresultsmatchedtheexpected result,thankyou,thankyou,thankyou.”

– KentBeck(Test-DrivenDevelopmentByExample)

THEENDQuestions?