a beginners guide to test driven development

36
A Beginners Guide to Test Driven Development Developing Sustainable Software…. Naresha K., Software Craftsman Twitter: @naresha_k

Upload: naresha-k

Post on 19-Jan-2017

1.633 views

Category:

Documents


2 download

TRANSCRIPT

A Beginners Guide to

Test Driven Development

Developing Sustainable Software….

Naresha K.,

Software Craftsman

Twitter: @naresha_k

Disclaimer

The opinions or views expressed

in this presentation are solely of

the speaker and do not necessarily

represent the views of my

employer.

You are Here

http://www.flickr.com/photos/oldben/2322196242/

The Roadmap

You are here Threat Driven Development

Destination Test Driven Development

The Significance

Never

in the field of software development

have so many owed

so much to

so few lines of code

The Problems

http://www.flickr.com/photos/donnagrayson/195244498/

Cost of Change

2

20

50

100150

500

Analysis Design Coding Integration Acceptance Production

Cost

Cost

Time To Market

http://www.flickr.com/photos/cobalt/5800169708/

Sustainable Software

http://www.flickr.com/photos/sillygwailo/146872543/

We are only afraid of…

http://www.flickr.com/photos/spursfan_ace/2328879637/http://www.flickr.com/photos/crystaljingsr/3914729343/

We are only afraid of…

http://www.flickr.com/photos/spursfan_ace/2328879637/

The waterfall way

Analysis

• 2 weeks

Design

• 3 weeks

Code

• 4 weeks

Test

• 4 weeks

Release

• 14th

week

The fall of waterfall

Analysis

• 2 weeks

• 2 weeks

Design

• 3 weeks

• 4 weeks

Code

• 4 weeks

• 5 weeks

Test

• 4 weeks

• 2 weeks

Release

• 14th

week

• 14th

week

Testing can only indicate the quality

http://www.flickr.com/photos/24560044@N08/5726488676/

But Feedback is Important

When to receive feedback?

• Closest to the incident

• Frequently

• You get more time to act upon

Test Early Approach

• Test as and when you complete small chunk of

code (say a function – is it small?)

• Integrate

– Early, Small & Often

– But involves cost

Nature of Business Environment

http://www.flickr.com/photos/oldben/2301828397/

Mistaken Assumption

http://www.flickr.com/photos/9465588@N05/3302103347/

The Solution

Embrace Change

Automated Testing

• Mitigates

– Integration testing cost

– Regression testing cost

Benefits

• S - Savings through early integration

• C - Cost of automating tests

• ROI = S / C

• (Small + Often) integration => more S

Still Problems !!

http://www.flickr.com/photos/mosmancouncil/3361174929/

Waste

• Unused Code

• Lack of modularity

The Ultimate Solution

• Write test code before production code

How Writing Tests Help?

• Clarifies the acceptance criteria

• Encourages to write loosely coupled components

• Adds executable description of what code does

• Regression suite

How Running Tests Help?

• Detects errors (early)

• Lets us know when we have done enough

• Avoid unnecessary features

Test Driven Cycle

1. Write failing Tests

2. Write code pass tests

3. Refactor

TDD – Rule #1

No code will be written

without a failing test

TDD – Rule #2

No more tests will be written

Than sufficient to fail

TDD – Rule #3

No more code will be written

than sufficient to pass

failing tests

Demo

Feedback from tests

Unit tests End-End testing

Am

ount

of

Fee

dbac

k

Internal Quality Feedback

External Quality Feedback

White Box Black Box