SlideShare a Scribd company logo
Breve introduzione al Test Driven Development Roberto Albertini [email_address] http://www.sourcesense.it/it/agile/team http://www.xpug.it http://www.lugcr.it http://www.linuxday.it
Test Driven Development “  Write new code only if an automated test has failed  ” Kent Beck  \
Test Driven Development “  Only ever write code to fix a failing test  ” Lasse Koskela  \
Test Driven Development “  we produce well-designed,  well-tested, and well-factored code  in small, verifiable steps  ” James Shore  \
i passi del TDD RED  GREEN  REFACTOR Write a test  Make it run  Make it right  Test  Code  Design passi  piccoli, incrementali, automatizzati
W rite  a test:  RED  Scrivi  un piccolo unit test   che non passa  o non compila il test racconta  una funzionalità oppure dimostra  un baco
cos'è uno Unit Test è un  Test codice che  verifica il funzionamento di altro codice è  Unitario di  una sola   “unità” di codice senza interazioni  con altre “unità” o sistemi esterni
un buon test  è  automatizzato  e  ripetibile un  solo  click per lanciare tutti i test l'output è  consistente output semplice:  verde  o  rosso verifica da solo  l'output output  “verboso” solo  quando è ross o
Make it run:  GREEN scrivi una semplice implementazione che faccia passare il test L’implementazione deve essere la  soluzione più rapida e semplice , anche banale. l’obiettivo è  avere i test verdi  il prima possibile.
Make it right:  REFACTOR elimina gli  smell migliora il  design Questa è l'attività che prende la  maggior parte del tempo. Si fa refactor  sia  del codice di produzione  sia  del codice di test.
Refactor “  Eliminate all of the duplication created in merely getting the test to work  ” Kent Beck  \
Refactor “  ...is about transforming the current design toward a better design  ” Lasse Koskela  \
Cos'è il Refactoring? “  Is the process of changing a software system in such a way  that it does not alter the external behaviour of the code yet improves its internal structure  ” Martin Fowler  \
Cos'è il Refactoring? migliorare il design del codice esistente  senza correre rischi riscivere il codice  non è   fare refactoring esempio di alcuni passi: Extract method, Move method, Inline method, Extract Class, Introduce Parametr Object, Replace temp with query, Replace conditional with polymorphism
Cos'è il Refactoring? miglioramenti a  piccoli passi   senza  “rompere”  l'esistente riscivere il codice  non è   fare refactoring aggiungere/modificare funzionalità  non è   fare refactoring esempio di alcuni passi: Extract method, Move method, Inline method, Extract Class, Introduce Parametr Object, Replace temp with query, Replace conditional with polymorphism
Cosa sono i code smell? sintomi e indizi  di qualcosa che  “non va”   nel codice esempio di alcuni smell duplicazioni, magic number, comenti sospetti, metodi lunghi, feautre envy, lunghe liste di parametri, inappropriate intimacy, message chain, data clump
Test Driven Development RED  GREEN  REFACTOR Write a test  Make it run  Make it right  Test  Code  Design Ripetere  ogni pochi minuti
Test Driven Development RED GREEN REFACTOR Ogni 2-10 minuti
Test Driven Development è uno stile di  sviluppo è una attività di  design non è   una attività di testing codice  testabile decisioni di design  poco alla volta prospettiva   corretta nel disegnare le api focus   sull'obiettivo
i Test non sono lo scopo sono lo  strumento pongono nella corretta  prospettiva aiutano a  scomporre i problemi  e isolarli aiutano a individuare gli errori con cicli brevi di  feedback e sono un utile  prodotto “di scarto” rimangono come  rete di sicurezza  efficacie e duratura
un esempio
Punteggio del Bowling
Frame in una partita si giocano  10 frame in ogni frame si hanno a disposizione 2 tiri  per abbattere i  10 birilli
Punti in un Frame in ogni frame si prende un  punto   per ogni birillo abbattuto Esempi 0+0 = segna 0 punti 6+3 = segna 9 punti 3+1 = segna 4 punti
Frame con Spare se in un frame  con i due si abbattono tutti i 10 birilli si prende un  punto bonus  per ogni birillo  abbattuto nel  tiro successivo Esempi Tiro 1 e 9 seguito da 3 e 4  ->  13 punti seguiti da 7 punti Tiro 6 e 4 seguito da 4 e 0  ->  14 punti seguiti da 4 punti Tiro 6 e 4 seguito da 0 e 4  ->  10 punti seguiti da 4 punti
Frame con Strike se in un frame  con il primo tiro si abbattono tutti i 10 birilli non si fa il secondo tiro e si riceve un  punto bonus  per ogni birillo  abbattuto nei  due tiri successivi Esempi Tiro 10, poi 3 e 4  ->  17 punti, poi 7 punti Tiro 10, poi 0 e 4  ->  14 punti, poi 4 punti Tiro 10, poi 10, poi 2+3  ->  22 punti, poi 15 punti, poi 5 punti
Ultimo frame se all'ultimo frame ottengo uno  spare  o uno  strike faccio i tiri necessari ad ottenere i  bonus Esempio All'ultimo frame tiro 3+7, tiro bonus 4  ->  14 punti All'ultimo frame tiro 10, tiri bonus 3 e 4  ->  17 punti All'ultimo frame tiro 10, tiri bonus 10 e 10  ->  30 punti
kata http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata

More Related Content

PDF
TDD patterns and TDD strategies
ODP
TDD Casi Studio
PPTX
Unit Testing
PPT
Test automatizzati & serenity bdd
PDF
What Makes Great Infographics
PDF
Masters of SlideShare
PDF
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
PDF
You Suck At PowerPoint!
TDD patterns and TDD strategies
TDD Casi Studio
Unit Testing
Test automatizzati & serenity bdd
What Makes Great Infographics
Masters of SlideShare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
You Suck At PowerPoint!

Similar to Linux Day 20091024 Test Driven Development (20)

KEY
A brief intro to TDD for a JUG-TAA event
ODP
TDD - una introduzione
ODP
PDF
Intoduzione Alle Metodologie Agili
PDF
Java Unit Testing - Introduction
ODP
Workshop: Introduzione ad TDD
PDF
Una fugace occhiata al Test Driven Development (2006)
PPTX
Test Driven Development @ Xe.Net
PDF
Software Testing & Test Driven Development
ODP
Unit testing 101
PDF
Test Driven Development for iOS
PDF
Workshop Test Drive Development
PPTX
Fe05 test drivenjavascriptdevelopment
PDF
AntiPatterns: i vizi del programmatore
PPTX
PASS Virtual Chapter - Unit Testing su SQL Server
PDF
The simplest thing that could possibly work
PDF
Scrum esami
PPTX
PASS Virtual Chapter - SQL Server Continuous Integration
PDF
Software Testing e TDD
PPTX
Agile Engineering
A brief intro to TDD for a JUG-TAA event
TDD - una introduzione
Intoduzione Alle Metodologie Agili
Java Unit Testing - Introduction
Workshop: Introduzione ad TDD
Una fugace occhiata al Test Driven Development (2006)
Test Driven Development @ Xe.Net
Software Testing & Test Driven Development
Unit testing 101
Test Driven Development for iOS
Workshop Test Drive Development
Fe05 test drivenjavascriptdevelopment
AntiPatterns: i vizi del programmatore
PASS Virtual Chapter - Unit Testing su SQL Server
The simplest thing that could possibly work
Scrum esami
PASS Virtual Chapter - SQL Server Continuous Integration
Software Testing e TDD
Agile Engineering
Ad

Linux Day 20091024 Test Driven Development

  • 1. Breve introduzione al Test Driven Development Roberto Albertini [email_address] http://www.sourcesense.it/it/agile/team http://www.xpug.it http://www.lugcr.it http://www.linuxday.it
  • 2. Test Driven Development “ Write new code only if an automated test has failed ” Kent Beck \
  • 3. Test Driven Development “ Only ever write code to fix a failing test ” Lasse Koskela \
  • 4. Test Driven Development “ we produce well-designed, well-tested, and well-factored code in small, verifiable steps ” James Shore \
  • 5. i passi del TDD RED GREEN REFACTOR Write a test Make it run Make it right Test Code Design passi piccoli, incrementali, automatizzati
  • 6. W rite a test: RED Scrivi un piccolo unit test che non passa o non compila il test racconta una funzionalità oppure dimostra un baco
  • 7. cos'è uno Unit Test è un Test codice che verifica il funzionamento di altro codice è Unitario di una sola “unità” di codice senza interazioni con altre “unità” o sistemi esterni
  • 8. un buon test è automatizzato e ripetibile un solo click per lanciare tutti i test l'output è consistente output semplice: verde o rosso verifica da solo l'output output “verboso” solo quando è ross o
  • 9. Make it run: GREEN scrivi una semplice implementazione che faccia passare il test L’implementazione deve essere la soluzione più rapida e semplice , anche banale. l’obiettivo è avere i test verdi il prima possibile.
  • 10. Make it right: REFACTOR elimina gli smell migliora il design Questa è l'attività che prende la maggior parte del tempo. Si fa refactor sia del codice di produzione sia del codice di test.
  • 11. Refactor “ Eliminate all of the duplication created in merely getting the test to work ” Kent Beck \
  • 12. Refactor “ ...is about transforming the current design toward a better design ” Lasse Koskela \
  • 13. Cos'è il Refactoring? “ Is the process of changing a software system in such a way that it does not alter the external behaviour of the code yet improves its internal structure ” Martin Fowler \
  • 14. Cos'è il Refactoring? migliorare il design del codice esistente senza correre rischi riscivere il codice non è fare refactoring esempio di alcuni passi: Extract method, Move method, Inline method, Extract Class, Introduce Parametr Object, Replace temp with query, Replace conditional with polymorphism
  • 15. Cos'è il Refactoring? miglioramenti a piccoli passi senza “rompere” l'esistente riscivere il codice non è fare refactoring aggiungere/modificare funzionalità non è fare refactoring esempio di alcuni passi: Extract method, Move method, Inline method, Extract Class, Introduce Parametr Object, Replace temp with query, Replace conditional with polymorphism
  • 16. Cosa sono i code smell? sintomi e indizi di qualcosa che “non va” nel codice esempio di alcuni smell duplicazioni, magic number, comenti sospetti, metodi lunghi, feautre envy, lunghe liste di parametri, inappropriate intimacy, message chain, data clump
  • 17. Test Driven Development RED GREEN REFACTOR Write a test Make it run Make it right Test Code Design Ripetere ogni pochi minuti
  • 18. Test Driven Development RED GREEN REFACTOR Ogni 2-10 minuti
  • 19. Test Driven Development è uno stile di sviluppo è una attività di design non è una attività di testing codice testabile decisioni di design poco alla volta prospettiva corretta nel disegnare le api focus sull'obiettivo
  • 20. i Test non sono lo scopo sono lo strumento pongono nella corretta prospettiva aiutano a scomporre i problemi e isolarli aiutano a individuare gli errori con cicli brevi di feedback e sono un utile prodotto “di scarto” rimangono come rete di sicurezza efficacie e duratura
  • 23. Frame in una partita si giocano 10 frame in ogni frame si hanno a disposizione 2 tiri per abbattere i 10 birilli
  • 24. Punti in un Frame in ogni frame si prende un punto per ogni birillo abbattuto Esempi 0+0 = segna 0 punti 6+3 = segna 9 punti 3+1 = segna 4 punti
  • 25. Frame con Spare se in un frame con i due si abbattono tutti i 10 birilli si prende un punto bonus per ogni birillo abbattuto nel tiro successivo Esempi Tiro 1 e 9 seguito da 3 e 4 -> 13 punti seguiti da 7 punti Tiro 6 e 4 seguito da 4 e 0 -> 14 punti seguiti da 4 punti Tiro 6 e 4 seguito da 0 e 4 -> 10 punti seguiti da 4 punti
  • 26. Frame con Strike se in un frame con il primo tiro si abbattono tutti i 10 birilli non si fa il secondo tiro e si riceve un punto bonus per ogni birillo abbattuto nei due tiri successivi Esempi Tiro 10, poi 3 e 4 -> 17 punti, poi 7 punti Tiro 10, poi 0 e 4 -> 14 punti, poi 4 punti Tiro 10, poi 10, poi 2+3 -> 22 punti, poi 15 punti, poi 5 punti
  • 27. Ultimo frame se all'ultimo frame ottengo uno spare o uno strike faccio i tiri necessari ad ottenere i bonus Esempio All'ultimo frame tiro 3+7, tiro bonus 4 -> 14 punti All'ultimo frame tiro 10, tiri bonus 3 e 4 -> 17 punti All'ultimo frame tiro 10, tiri bonus 10 e 10 -> 30 punti