Introduction to Test Driven Development

82
Introduction to Test Driven Development Sivasubramaniam Arunachalam Mar 29, 2014 @sivaa_in http://barcampbangalore.org/bcb/bcb15/introduction-to-test-driven-development-tdd

description

Presented at Barcamp Bangalore Spring 2014. http://barcampbangalore.org/bcb/bcb15/introduction-to-test-driven-development-tdd

Transcript of Introduction to Test Driven Development

Page 1: Introduction to Test Driven Development

Introduction to Test Driven Development

Sivasubramaniam Arunachalam

Mar 29, 2014

@sivaa_in

http://barcampbangalore.org/bcb/bcb15/introduction-to-test-driven-development-tdd

Page 2: Introduction to Test Driven Development

It’s me!

Page 3: Introduction to Test Driven Development
Page 4: Introduction to Test Driven Development

It’s about you!

#barcampblr

#tdd

Page 5: Introduction to Test Driven Development

Just Before We Get

Started

Page 6: Introduction to Test Driven Development

How many of you are

• Developers

• Testers/Quality

• Manual

• Automated

Manual/Automated Developers?

Page 7: Introduction to Test Driven Development

> 100K

Page 8: Introduction to Test Driven Development

> 5

Page 9: Introduction to Test Driven Development

Waste of time

Page 10: Introduction to Test Driven Development

No

Opportunity

Page 11: Introduction to Test Driven Development
Page 12: Introduction to Test Driven Development
Page 13: Introduction to Test Driven Development
Page 14: Introduction to Test Driven Development

Test Driven Development

Page 15: Introduction to Test Driven Development

TDD is NOT a Testing Strategy

Page 16: Introduction to Test Driven Development

TDD is a Design Strategy

Page 17: Introduction to Test Driven Development

TDD is NOT for Testers

Page 18: Introduction to Test Driven Development

TDD is for Developers

Page 19: Introduction to Test Driven Development

(1) – (2) – (3)

Page 20: Introduction to Test Driven Development

(1) – (2) – (3)

Others

Code

Page 21: Introduction to Test Driven Development

(1) – (2) – (3)

Legacy

Systems

Page 22: Introduction to Test Driven Development

(1) – (2) – (3)

Change in

Architecture

Page 23: Introduction to Test Driven Development

How to Start?

Page 24: Introduction to Test Driven Development

How I have Started?

Page 25: Introduction to Test Driven Development

The Correct way

Page 26: Introduction to Test Driven Development
Page 27: Introduction to Test Driven Development
Page 28: Introduction to Test Driven Development
Page 29: Introduction to Test Driven Development
Page 30: Introduction to Test Driven Development
Page 31: Introduction to Test Driven Development

Refactoring? • Removing duplication

• Make the logic simpler

• Make the code easier to read

Page 32: Introduction to Test Driven Development
Page 33: Introduction to Test Driven Development

TDD Components

• Unit Tests

• Functional Tests

• Integration Tests

Page 34: Introduction to Test Driven Development

Unit Tests

Page 35: Introduction to Test Driven Development

Unit Tests Best Practices

• Focus one Class/Method

• Keep it under 10 seconds

• Execute 100 tests/second

• Runs only on memory

Page 36: Introduction to Test Driven Development

Integration Tests

Page 37: Introduction to Test Driven Development

Functional Tests

Page 38: Introduction to Test Driven Development

Are you ready now?

Page 39: Introduction to Test Driven Development

Everyone likes to have tests

but

Few people like writing them.

Page 40: Introduction to Test Driven Development
Page 41: Introduction to Test Driven Development

Only way to test Interfaces & Design

Page 42: Introduction to Test Driven Development

Immediate

Confirmation

Page 43: Introduction to Test Driven Development

Helps to re-think what

Needs to be Coded

Page 44: Introduction to Test Driven Development

Acts as a

Low Level Spec

Page 45: Introduction to Test Driven Development

Less Rework

Page 46: Introduction to Test Driven Development

Regression due to refactoring

This is the only way to find it

Page 47: Introduction to Test Driven Development

No More

Dead Code

Less code = Less bugs

Page 48: Introduction to Test Driven Development

Unit Tests might act as a

Documentation

Page 49: Introduction to Test Driven Development

Less

Debugging

Page 50: Introduction to Test Driven Development
Page 51: Introduction to Test Driven Development

Lets calculate the Cost

2 x $25 = $50

N x $M = $5K will become

Page 52: Introduction to Test Driven Development
Page 53: Introduction to Test Driven Development

Faster

Development

Page 54: Introduction to Test Driven Development

By Products

• Forces you to write small classes (focused on one thing.)

• Helps create loosely coupled code

• Measure implementation progress

Page 55: Introduction to Test Driven Development

How Much is enough?

Page 56: Introduction to Test Driven Development

Can I test Getters and Setters?

Page 57: Introduction to Test Driven Development

Can I test Third-Party Libraries?

Page 58: Introduction to Test Driven Development

(How)

Can I test Private Methods?

Page 59: Introduction to Test Driven Development

(How)

Can I test User Interfaces?

Page 60: Introduction to Test Driven Development

Be a Cool dude and exclude

Page 61: Introduction to Test Driven Development

Where to focus

More and Less?

Page 62: Introduction to Test Driven Development
Page 63: Introduction to Test Driven Development

Mock Objects

Page 64: Introduction to Test Driven Development

Scaling

Page 65: Introduction to Test Driven Development

When do we

FAIL?

Page 66: Introduction to Test Driven Development

Why businesses don’t like TDD?

Page 67: Introduction to Test Driven Development

How to start TDD for

existing applications?

Page 68: Introduction to Test Driven Development

Potential

Challenges

Page 69: Introduction to Test Driven Development

Applicable for

Startups?

Page 70: Introduction to Test Driven Development

Is it really

worth it?

Page 72: Introduction to Test Driven Development

http://programmers.stackexchange.com/questions/206355/the-relative-cost-efficiency-of-acceptance-test-driven-development

Page 73: Introduction to Test Driven Development

Someone is using it?

http://agilepainrelief.com/notesfromatooluser/2008/11/misconceptions-with-test-driven-development.html

Page 74: Introduction to Test Driven Development

Lets see some (test) code

Page 75: Introduction to Test Driven Development

Dis-advantages (You will lose)

• Ability to say you are "done" before testing all your code.

• Opportunity to learn through debugging.

• Flexibility to ship code that you aren't sure of.

• Freedom to tightly couple your modules.

• Option to skip writing low level design documentation.

• Stability that comes with code that everyone is afraid to change.

• Capability to write hundreds or thousands of lines of code before running it.

Page 76: Introduction to Test Driven Development

TFD vs TDD

Page 77: Introduction to Test Driven Development
Page 78: Introduction to Test Driven Development

Code without tests is

broken by design.

- Jacob Kaplan-Moss

Page 79: Introduction to Test Driven Development

Debugging is twice as hard as writing the code in the first place.

- Brian Kernighan

Page 80: Introduction to Test Driven Development

Debugging is twice as hard as writing the code in the first place.

Therefore, if you write the code as cleverly as possible, you

are, by definition, not smart enough to debug it.

- Brian Kernighan

Page 81: Introduction to Test Driven Development

Thank You! [email protected]

bit.ly/sivasubramaniam bit.ly/sivaa_in

Page 82: Introduction to Test Driven Development

References https://www.youtube.com/watch?v=DodJQyHsmHI