Top Banner
Test Driven Development Clean Code that works!!!
22
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Test Driven Development

Test Driven Development

Clean Code that works!!!

Page 2: Test Driven Development

Agenda

2

Intro to TDD

TDD by example

Conclusions

Page 3: Test Driven Development

Intro

3

Page 4: Test Driven Development

What is TDD

Developed (or rediscovered) by Kent Beck to encourage

simple design and inspire confidence.

Related to the test-first programming concepts of eXtrem

Programming

A software development process that relies on the

repetition of a very short development cicle

4

Page 5: Test Driven Development

The golden rules

Never write model code

unless you have a test that

requires it

Write new code only if an

automated test has failed

Eliminate duplication

5

Page 6: Test Driven Development

What's my motivation?

TDD<piè di

pagina><piè di

pagina><piè di

pagina><piè di

pagina>

6

COURAGE

Clean Code that works!!!

Page 7: Test Driven Development

Managing fear

“I have a problem and I can't see the end from the beginning”

Fear says you to be carefull

7

Page 8: Test Driven Development

TDD mantra

8

Page 9: Test Driven Development

Benefits

9

Programmers who wrote more tests tended to be more productive

Programmers using TDD rarely felt the need to invoke a debugger TDD offers validation of correctness and drives the design of a program

TDD offers the ability to take small steps Even if more code is required, the total code implementation time could be

shorter TDD can lead to more modularized, flexible and extensible code

Because no more code is written than necessary to pass a failing test case, tests tend to cover every code path.

Page 10: Test Driven Development

TDD by example

10

Page 11: Test Driven Development

Multi Currency Money

11

Bond portfolio management system.

Company Shares Price Total

Pippo SpA 1000 25 25000

Pluto srl 400 100 40000

Total 65000

Multy currency report

Company Shar

es

Price Total

Pippo SpA 1000 25 EUR 25000 EUR

Gastone SaS 400 100 USD 40000 USD

Total 65000 EUR

Rates

From To Rate

USD EUR 2

Page 12: Test Driven Development

12

Page 13: Test Driven Development

Conclusions

13

Page 14: Test Driven Development

TDD Best Practices I

Work only on one test at a time

14

Page 15: Test Driven Development

TDD Best Practices II

Write test assertions

self-explanatory

15

Page 16: Test Driven Development

TDD Best Practices III

Same structure for tests and

source code

16

Page 17: Test Driven Development

TDD Best Practices IV

Keep tests small

17

Page 18: Test Driven Development

TDD Best Practices V.I

integrate your code every few unit test and never

leave broken tests

18

If you are working in a team...

Page 19: Test Driven Development

TDD Best Practices V.II

end every day with a broken test

19

If you are working alone...

Page 20: Test Driven Development

Summary

TDD Mantra

TDD rhythm

Value Object pattern

Information Hiding principle

DRY principle

20

Page 21: Test Driven Development

Bibliography and references

Kent Beck – Test-Driven Development by Example, The Addison-Wesley Signature Series

Jason Gorma – Agile Java Development: Test-Driven Development using JUnit and Eclipse

WardsWiKi - http://c2.com/cgi/wiki?TestDrivenDevelopment

WardsWiKi - http://c2.com/cgi/wiki?DontRepeatYourself

www.testdriven.com

www.junit.com

www.bigthink.it/php/test-driven-development-prima-i-test-poi-il-codice

www.agiledata.org/essays/tdd.html

21

Page 22: Test Driven Development

Thank you for your attention!!!

22