Linux Day 20091024 Test Driven Development
Click here to load reader
-
Upload
roberto-albertini -
Category
Technology
-
view
426 -
download
1
Transcript of Linux Day 20091024 Test Driven Development
![Page 1: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/1.jpg)
Breve introduzione al
Test DrivenDevelopment
Roberto [email protected]
http://www.sourcesense.it/it/agile/teamhttp://www.xpug.it
http://www.lugcr.ithttp://www.linuxday.it
![Page 2: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/2.jpg)
Test Driven Development
“ Write new code only ifan automated test has failed ”
Kent Beck
\
![Page 3: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/3.jpg)
Test Driven Development
“ Only ever write codeto fix a failing test ”
Lasse Koskela
\
![Page 4: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/4.jpg)
Test Driven Development
“ we produce well-designed, well-tested, and well-factored code
in small, verifiable steps ”James Shore
\
![Page 5: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/5.jpg)
i passi del TDD
RED GREEN REFACTORWrite a test Make it run Make it right
Test Code Design
passi piccoli, incrementali, automatizzati
![Page 6: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/6.jpg)
Write a test: RED
Scrivi un piccolo
unit test che non passa
o non compila
il test racconta una funzionalità
oppure dimostra un baco
![Page 7: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/7.jpg)
cos'è uno Unit Test
è un Testcodice che verifica
il funzionamento di altro codice
è Unitariodi una sola “unità” di codice
senza interazioni con altre “unità” o sistemi esterni
![Page 8: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/8.jpg)
un buon test
è automatizzato e ripetibileun solo click per lanciare tutti i test
l'output è consistente
output semplice: verde o rossoverifica da solo l'output
output “verboso” solo quando è rosso
![Page 9: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/9.jpg)
Make it run: GREEN
scrivi una
semplice implementazioneche 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.
![Page 10: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/10.jpg)
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.
![Page 11: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/11.jpg)
Refactor
“ Eliminate all of the duplication createdin merely getting the test to work ”
Kent Beck
\
![Page 12: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/12.jpg)
Refactor
“ ...is about transforming the currentdesign toward a better design ”
Lasse Koskela
\
![Page 13: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/13.jpg)
Cos'è il Refactoring?
“ Is the process of changinga software system in such a way
that it does not alter theexternal behaviour of the code
yet improves its internal structure ”
Martin Fowler \
![Page 14: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/14.jpg)
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
![Page 15: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/15.jpg)
Cos'è il Refactoring?
miglioramenti a piccoli passi
senza “rompere” l'esistenteriscivere 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
![Page 16: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/16.jpg)
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
![Page 17: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/17.jpg)
Test Driven Development
RED GREEN REFACTOR Write a test Make it run Make it right
Test Code Design
Ripetere ogni pochi minuti
![Page 18: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/18.jpg)
Test Driven Development
RED GREEN
REFACTOR
Ogni 2-10 minuti
![Page 19: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/19.jpg)
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
![Page 20: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/20.jpg)
i Test non sono lo scopo
sono lo strumentopongono 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
![Page 21: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/21.jpg)
un esempio
![Page 22: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/22.jpg)
Punteggio del Bowling
![Page 23: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/23.jpg)
Frame
in una partita si giocano 10 frame
in ogni frame si hanno a disposizione
2 tiri per abbattere i 10 birilli
![Page 24: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/24.jpg)
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
![Page 25: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/25.jpg)
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
![Page 26: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/26.jpg)
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
![Page 27: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/27.jpg)
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
![Page 28: Linux Day 20091024 Test Driven Development](https://reader038.fdocuments.us/reader038/viewer/2022100518/5598fb8f1a28ab7b718b4654/html5/thumbnails/28.jpg)
kata
http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata