31
TDD Test Driven Development David Paluy Jul 2015

Tdd - Test Driven Development

Embed Size (px)

Citation preview

TDDTest Driven DevelopmentDavid PaluyJul 2015

Agenda

1. When do we need to write tests

2. The TDD process

3. Glossary

Test Driven Development

You don’t have to do TDD,

You should do TDD.

When do we need to write tests?

If my codeworks perfectly,why should I write tests for it?

Realization 1

Testing breeds confidence

Confidence

● Modular code

● Many changes

● Refactoring

If there are NO TESTS, you should be worried making changes!

“Write a failing automated test before changing any code” - Kent Beck

Remember

When do we need to write tests?

So, if the codeworks perfectly, and I’m never going to change it, then why should I write tests?

Realization 2

If you write tests before you write your code,you end up writing a better code

If I write the test first,

● It forces me think before I code

● Code is more focused and clear

● I know when I’m finished, because all thetests pass

When do we need to write tests?

So, if the codeworks perfectly, and I’m never going to change it and the design is already flawless,then why should I write tests?

Realization 3

Well written tests are just as good, if notbetter than documentation

Yoga Instructions

1. Kneel down2. Put your hands flat in the ground3. Lift your feet off the ground and balance on

your hands4. Put your knees ahead of your hands5. Stretch out your back so your body is

perpendicular to the ground

Yoga Instructions

Yoga Instructions

Examples > Comments

When do we need to write tests?

So, if the codeworks perfectly, and I’m never going to change it and the design is already flawless and it is totallyreadable and understandable,then why should I write tests?

The moral

Learning Test Driven Development

The TDD process

● Write specifications

● Write tests

● Write code

The TDD process

The TDD process

Glossary

● Unit Tests

● Integration Tests

● Acceptance Tests

● Mocks, Stubs

Unit Test - Method to verify isolated units of code● Checks a single assumption about the

behavior of the unit

● Fast running tests

● Quick to debug

● Is hitting DB - is OK?

Integration Tests

● Tests software modules as a group

● Tests integration points

● Slower than Unit tests

Acceptance tests

● End-to-end test cases of: happy user journeys and critical failure scenarios

● Production like environment

● Manual or Automated

Mocks vs Stubs

Mock Objects are special case objects that mimic real objects for testing.

Stubs provide canned answers to calls made during the test

Test Driven Development

Inspect+

Adapt

Test Driven Development

Apply

Inspect

Adapt

Test Driven Development

Apply

Inspect

AdaptIf you haven’t done it first, you don’t know what you are talking about!

“Any fool can write code that a computer can understand.Good programmers write code that humans can understand.”

Martin Fowler, 2008.