The Road to Test Driven Development

Post on 27-Jan-2015

1283 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

Transcript

04/10/23Copyright Oversee.net 20081

The Road To Test-Driven The Road To Test-Driven DevelopmentDevelopment

By Christopher PaulickaSoftware Engineering Manager

04/10/23Copyright Oversee.net 20082

Introduction Introduction

Not just what Test-Driven Development is…

But also how to get to Test-Driven Development

04/10/23Copyright Oversee.net 20083

AgendaAgenda

What is Test-Driven DevelopmentOne (Abstract) Road to Test-Driven

DevelopmentYour Road to Test-Driven DevelopmentMy Road to Test-Driven Development

04/10/23Copyright Oversee.net 20084

VocabularyVocabulary

Test-Driven Development – TDDExtreme Programming - XP

04/10/23Copyright Oversee.net 20085

ThanksThanks

Perl Mongers for showing up!Oversee.net for the nice spaceMichael Lee, Director of Engineering, for

“volunteering” meAll the development team here at Oversee

for feedback

04/10/23Copyright Oversee.net 20086

The Three ParticipantsThe Three Participants

Christopher PaulickaOversee.netPerl Mongers

04/10/23Copyright Oversee.net 20087

Christopher PaulickaChristopher Paulicka

Software Development – 16 yearsTesting – 10 yearsPerl – 4 yearsTest-Driven Development – 1 year

04/10/23Copyright Oversee.net 20088

Oversee Development Oversee Development EnvironmentEnvironmentAgile/ScrumPerforceLinux/Apache/MySQL/Perl, RPMMason/Catalyst, DBITest::More, Test::MockObjectTest::Unit, Test::WWW::SeleniumModule::Build, CPAN2RPM

04/10/23Copyright Oversee.net 20089

Perl MongersPerl Mongers

Perl aficionadosPlease ask questions at any timeWhat’s your testing experience?

04/10/23Copyright Oversee.net 200810

What is TDDWhat is TDD

TDD is old, but kind of newTest first, but still follow requirementsPart of Agile/XP, but reusable anywhere

04/10/23Copyright Oversee.net 200811

Important to KnowImportant to Know

History of TDD in Extreme ProgrammingHistory of Scrum at Oversee

04/10/23Copyright Oversee.net 200812

Software Development Software Development MethodologiesMethodologiesHackWaterfallAgile

04/10/23Copyright Oversee.net 200813

Waterfall DevelopmentWaterfall Development

RequirementsDesignImplementTestMaintain

04/10/23Copyright Oversee.net 200814

Waterfall CostsWaterfall Costs

Rigid designHigh change costsRequires expert designers up front

04/10/23Copyright Oversee.net 200815

Examples of Agile Examples of Agile MethodologiesMethodologiesExtreme ProgrammingScrumCrystal ClearFeature Driven DevelopmentAdaptive Software DevelopmentDSDM

04/10/23Copyright Oversee.net 200816

Extreme ProgrammingExtreme Programming

Test-Driven DevelopmentContinuous IntegrationPair ProgrammingRefactoring

04/10/23Copyright Oversee.net 200817

Cost of FeedbackCost of Feedback

04/10/23Copyright Oversee.net 200818

Test-Driven DevelopmentTest-Driven Development

Pick a FeatureWrite a Test for that FeatureRun all Tests and see new Test FailWrite Code for FeatureRun all Tests and see all Tests PassRefactorRepeat

04/10/23Copyright Oversee.net 200819

A Bit More About RefactoringA Bit More About Refactoring

Refactor the CodeRefactor the TestsRefactor the DocumentationRefactor the Design

04/10/23Copyright Oversee.net 200820

Who owns testing?Who owns testing?

QADeploySystemsDevelopment

04/10/23Copyright Oversee.net 200821

Types of TestingTypes of Testing

Requirements TestsIntegration TestsSystem TestsDevelopment Tests

04/10/23Copyright Oversee.net 200822

Types of Development TestingTypes of Development Testing

Unit TestsRegression Tests

04/10/23Copyright Oversee.net 200823

One Possible Road to TDDOne Possible Road to TDD

Test to VerifyTest for RegressionTest for DesignTest-Driven Development

04/10/23Copyright Oversee.net 200824

Test To VerifyTest To Verify

Problem arisesWrite throw away testDisposable code modifications

– Logging– Dumping, etc

Simple and FastGone forever…

04/10/23Copyright Oversee.net 200825

Why Do We Do That?Why Do We Do That?

HabitSpeedAnticipation (almost done…)

04/10/23Copyright Oversee.net 200826

Test for RegressionTest for Regression

Problem arisesWrite reusable test that duplicates problemKeep regression testRun regressions anytime

04/10/23Copyright Oversee.net 200827

Good, but Good enough?Good, but Good enough?

Bug driven Prevents regressionsRun tests anytime in developmentFocused late in the curveExpects test framework

04/10/23Copyright Oversee.net 200828

Test for DesignTest for Design

Design APIWrite CodeWrite TestsRefactor

04/10/23Copyright Oversee.net 200829

Development Test ProcessesDevelopment Test Processes

Piece-wise Test LastLump-sum Test LastTest First aka TDD

04/10/23Copyright Oversee.net 200830

Test-Driven DevelopmentTest-Driven Development

As Beck said in XP– Good Rules, lead to – Good Behavior, which give– Good Unit Tests

04/10/23Copyright Oversee.net 200831

RulesRules

Write code only when test failsEliminate duplication afterwards

04/10/23Copyright Oversee.net 200832

BehaviorsBehaviors

Organic DesignWriting own testsRapid responseModular Design

04/10/23Copyright Oversee.net 200833

Good Unit TestsGood Unit Tests

Run fastRun in isolationEasy to understandUse real dataIncremental step (not too large)

04/10/23Copyright Oversee.net 200834

Your Road To TDDYour Road To TDD

Why TDDCost/Benefit AnalysisHow To Start

04/10/23Copyright Oversee.net 200835

Why Test Driven DesignWhy Test Driven Design

Tests as Use CasesTests as DocumentationTests as Design

04/10/23Copyright Oversee.net 200836

Possible reasons to avoid TDDPossible reasons to avoid TDD

Tests are programmer focusedMay not be requirement focusedRunning all tests are slowSprintingRefactoringComparing

04/10/23Copyright Oversee.net 200837

Cost/Benefit of TDDCost/Benefit of TDD

Industry AnalysisPersonal Analysis

04/10/23Copyright Oversee.net 200838

Benefits - Industry AnalysisBenefits - Industry Analysis

Reduce development lead-time significantly

Programmers that write tests are more productive

Rarely use a debuggerEasy to revert on test failure…

04/10/23Copyright Oversee.net 200839

Benefits – Industry Analysis (cont)Benefits – Industry Analysis (cont)

Programmers tests interface first, then code

Shorter implementation timeHigh Code coverageRegressionsMore modular code

04/10/23Copyright Oversee.net 200840

Costs – Industry AnalysisCosts – Industry Analysis

More code– Though higher productivity with TDD

Costly test setup– UI– DB– Multithreaded

Large legacy code bases

04/10/23Copyright Oversee.net 200841

Metrics – Industry AnalysisMetrics – Industry Analysis

TDD code passed 18 - 50% more external test cases than control group code

TDD code had 10 – 50% less time spent debugging code

TDD had from 0 - 16% decrease in productivity (in lines of non-test code)

04/10/23Copyright Oversee.net 200842

Metrics – Industry Analysis (cont)Metrics – Industry Analysis (cont)

TDD has 163% more asserts/moduleTDD 2-3x higher test coverage

– line and condition coverage near 100%TDD coders spent 13% less time

producing solutions that were 12% larger then control (including tests!)

04/10/23Copyright Oversee.net 200843

Subjective – Industry AnalysisSubjective – Industry Analysis

After the study, when asked:TDD would stick with TDDTLD would go to TDD (60%+)No tests would go to TLD

04/10/23Copyright Oversee.net 200844

Benefits – Personal AnalysisBenefits – Personal Analysis

Senior/Junior Developer Interaction– Senior approve tests/API– Junior implements API– Senior code reviews, done

Tests as Use CasesTest Documentation more stable then

Code Documentation

04/10/23Copyright Oversee.net 200845

Costs – Personal AnalysisCosts – Personal Analysis

More code– Though happier with more feedback

Costly test setup– UI - WWW::Mechanize– DB – Test::MockObject– Multithreaded - …heh…yes.

Large Legacy Codebases are painful, but TDD may be very beneficial…it’s a start!

04/10/23Copyright Oversee.net 200846

How To StartHow To Start

Believe in TestingTest FrameworkTest CoverageWrite Tests First

04/10/23Copyright Oversee.net 200847

Believe in TestingBelieve in Testing

If it's worth building, it's worth testing.If it's not worth testing, why are you

wasting your time working on it?

04/10/23Copyright Oversee.net 200848

Test FrameworksTest Frameworks

Perl has a lot…Test::SimpleTest::MoreTest::Unit

04/10/23Copyright Oversee.net 200849

Test CoverageTest Coverage

Provide metricsDevel::Cover

04/10/23Copyright Oversee.net 200850

Write Tests FirstWrite Tests First

Code review testsPair program testsAlways ask, “Where’s the test?”Help make tests easier

04/10/23Copyright Oversee.net 200851

Be Aware!Be Aware!

You are now becoming a test expert!TDD AntipatternsDon’t test just to test…

04/10/23Copyright Oversee.net 200852

My Road To Test-Driven My Road To Test-Driven DevelopmentDevelopmentHewlett-Packard EMSOIdealab

– X1– Energy Innovations

04/10/23Copyright Oversee.net 200853

Lessons from Hewlett-PackardLessons from Hewlett-Packard

Tests are nowhere near perfectTests can prove your pointBelieve in tests!

04/10/23Copyright Oversee.net 200854

Tests are nowhere near perfectTests are nowhere near perfect

500000 lines of codeHundreds of feature tests workingApplications run for 3 daysI knew it was broken

04/10/23Copyright Oversee.net 200855

Tests can prove your pointTests can prove your point

No one wanted to believe itThe product needed to shipWrote random component

creator/messenger/destroyerCore dump in less then a millisecondCreated tests from random iterationsFixed hundreds of memory leaks and

contention issues

04/10/23Copyright Oversee.net 200856

Lessons from X1Lessons from X1

Good Test FrameworkKeep each other honest

04/10/23Copyright Oversee.net 200857

Good Test FrameworkGood Test Framework

Test::UnitWWW::MechanizeDBI

– No MockObjects

04/10/23Copyright Oversee.net 200858

Keep each other honestKeep each other honest

Test First, not test eventuallyEverybody Writes Tests……but feel free to ask for help

04/10/23Copyright Oversee.net 200859

Lessons from Energy Lessons from Energy InnovationsInnovationsCost of RefactoringBeware Gold PlatingIt’s easy to get lazy…

04/10/23Copyright Oversee.net 200860

SummarySummary

Learned about TDDLearned about benefits (and costs) of TDDLearned first steps towards TDD

04/10/23Copyright Oversee.net 200861

Q&AQ&A

04/10/23Copyright Oversee.net 200862

BibliographyBibliography I would highly recommend “The Object Primer”

by Scott W. Ambler, now in it’s third edition. http://www.agiledata.org/essays/tdd.html http://en.wikipedia.org/wiki/Test-driven_develop

ment http://en.wikipedia.org/wiki/Agile_software_dev

elopment http://en.wikipedia.org/wiki/Continuous_integrat

ion http://en.wikipedia.org/wiki/Refactoring …

04/10/23Copyright Oversee.net 200863

Bibliography (cont)Bibliography (cont)

http://blog.james-carr.org/?p=44http://www.ipd.uka.de/Tichy/uploads/publi

kationen/136/MuellerHoefer2007.pdfhttp://www.acm.org/src/subpages/gf_entri

es_06/DavidJanzen_src_gf06.pdfhttp://utopia.csis.pace.edu/dps/2008/mcape

llan/projects/TDD/TDD_Idea_Paper_V04-03.doc

04/10/23Copyright Oversee.net 200864

Bibliography (cont)Bibliography (cont)

http://www.sciencedirect.com/science?_ob=ArticleURL&_udi=B75H1-4FC40MJ-2&_user=10&_rdoc=1&_fmt=&_orig=search&_sort=d&view=c&_acct=C000050221&_version=1&_urlVersion=0&_userid=10&md5=fbd92b394263506930dfafb31003a916

http://aegis.sourceforge.net/

top related