SlideShare a Scribd company logo
1 of 15
Download to read offline
TDD Patterns and TDD Strategies 
Alessandro Ceseno 
contact me, my website is: www.alexceseno.it 
Add me on Linkedin: 
http://www.linkedin.com/in/alessandroceseno
TDD Patterns 
Test 
Come fare TDD 
Aggiungi un test 
Fai fallire un test (barra rossa) 
Modica il test per vedere la barra verde (tutti i test eseguiti 
con successo) 
Refactoring verificando che: 
- funzioni 
- non vi é duplicazione di codice
Isolated Test 
Come capire se funziona la tua classe? 
Scrivi un test automatico. 
Il tuo test è isolato se non da problemi: 
nell' essere eseguito in modo concorrente con altri test 
non si basa su un altro test (ogni test dovrebbe ricreare il 
suo contesto e non dipendere da un altro test) 
non si basa su un sistema esterno (FS, Network,etc.) 
non necessita di un ambiente con una particolare 
configurazione (“It worked on my machine!”) 
se fallisce non test il messaggio di errore non indica 
chiaramente perchè fallisce il test
Test list 
Crea una lista dei test 
Mentre scrivi test e codice applicativo, 
se individui altri test aggiungili alla tua lista di test
Test First 
Scrivi il test prima del codice applicativo 
Qual'e il prossimo test? 
Il prossimo test è quello che ti insegna qualcosa e quello in 
cui ti senti più confidente
Test Data 
Quali dati per il test si devono utilizzare? 
Il codice di test dovrebbe essere il più leggibile e semplice 
possibile, quindi la struttura dei dati di test da utilizzare è 
quella che consente leggibilità e semplicità
Evident Data 
I risultati che ci si aspetta e i risultati attuali 
devono essere chiari ed evidenti
TDD Strategies 
I tre approcci principali di implementazione e design nel 
TDD: 
- Write the obvious implementation (Scrivi il caso più 
evidente e più semplice) 
- Fake it (till you make it). Essendo una tecnica 
incrementale, inizia anche con un fake test. 
Generalizza solo quando hai due o tre esempi di test 
- Triangulate. Il passo successivo è l'implementazione 
dell'algoritmo corretto.
Considerazioni: 
Considerare i test affinchè non vi siano ridondati test, 
i test ridondanti sono test che non creano nuove distinzioni 
di comportamento. 
redundancy code --> può generare eccessivi problemi di 
manutenzione 
quindi anche 
redundancy test --> possono generare eccessivi problemi 
di manutenzione 
Arrivi al design desiderato solo rimuovendo la duplicazione,
Il TDD è un modo di gestire la "paura" nello sviluppo? 
È un modo di gestire il coraggio. 
Ti consente di fare tentativi semplici e corti come numero di 
linee di codice, tentativi che ti consentono di capire il 
funzionamento in un tempo relativamente breve. 
Consentono una miglior comunicazione (perchè i test si 
capisco, o meglio si dovrebbero capire, se il TDD è fatto 
bene)
Se hai un test "grande" che si rompe, introduci un test 
"piccolo" (in questo modo isoli il problema), risolvi il 
problema e poi reintroduci il test grande. 
Broken test: viene utilizzato affinchè quando si ritorna su 
una sessione di programmazione si sa esattamente da 
dove iniziare.
Break: fare una pausa quando si sente di aver bisogno di 
una pausa. 
Cheap Desk, Nice Chair.
Come individuare test scritti male: 
codice di setup con molte linee 
duplicazione di codice che vi è nel setup nelle altre parti 
della classe 
test unitari lunghi da eseguire 
test fragile: i test si rompono ma non si sa il perchè si 
rompono
Bibliografia: 
Kent Beck - Test Driven Development: By 
Example
TDD Patterns and TDD Strategies 
Alessandro Ceseno 
contact me, my website is: www.alexceseno.it 
Add me on Linkedin: 
http://www.linkedin.com/in/alessandroceseno

More Related Content

What's hot

Una fugace occhiata al Test Driven Development (2006)
Una fugace occhiata al Test Driven Development  (2006)Una fugace occhiata al Test Driven Development  (2006)
Una fugace occhiata al Test Driven Development (2006)Roberto Bettazzoni
 
Le pratiche ingegneristiche di eXtreme Programming
Le pratiche ingegneristiche di eXtreme ProgrammingLe pratiche ingegneristiche di eXtreme Programming
Le pratiche ingegneristiche di eXtreme ProgrammingAndrea Francia
 
Unit Tests VS End To End Tests
Unit Tests VS End To End TestsUnit Tests VS End To End Tests
Unit Tests VS End To End Testsmimmozzo_
 
Detailed Model Capture
Detailed Model CaptureDetailed Model Capture
Detailed Model Capturefcospito
 
Test Driven Development for iOS
Test Driven Development for iOSTest Driven Development for iOS
Test Driven Development for iOSAlessandro Ceseno
 
Fe05 test drivenjavascriptdevelopment
Fe05   test drivenjavascriptdevelopmentFe05   test drivenjavascriptdevelopment
Fe05 test drivenjavascriptdevelopmentDotNetCampus
 
Software Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSoftware Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSergio Santoro
 
Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...
Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...
Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...Emerasoft, solutions to collaborate
 
Unit testing in Visual Studio 2013
Unit testing in Visual Studio 2013Unit testing in Visual Studio 2013
Unit testing in Visual Studio 2013DomusDotNet
 
Il computer dice no!
Il computer dice no!Il computer dice no!
Il computer dice no!Matteo Emili
 
Test Driven Development @ Xe.Net
Test Driven Development @ Xe.NetTest Driven Development @ Xe.Net
Test Driven Development @ Xe.NetMauro Servienti
 
Codice di qualità con VS2010 (TDD)
Codice di qualità con VS2010 (TDD)Codice di qualità con VS2010 (TDD)
Codice di qualità con VS2010 (TDD)XeDotNet
 
ATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven DevelopmentATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven DevelopmentGiorgio Marchetti
 
Effective Code Transformations in C++
Effective Code Transformations in C++Effective Code Transformations in C++
Effective Code Transformations in C++Marco Arena
 
Convertire estensioni da Joomla! 3 a Joomla! 4
Convertire estensioni da Joomla! 3 a Joomla! 4Convertire estensioni da Joomla! 3 a Joomla! 4
Convertire estensioni da Joomla! 3 a Joomla! 4Loredana Fineo
 

What's hot (20)

Una fugace occhiata al Test Driven Development (2006)
Una fugace occhiata al Test Driven Development  (2006)Una fugace occhiata al Test Driven Development  (2006)
Una fugace occhiata al Test Driven Development (2006)
 
Le pratiche ingegneristiche di eXtreme Programming
Le pratiche ingegneristiche di eXtreme ProgrammingLe pratiche ingegneristiche di eXtreme Programming
Le pratiche ingegneristiche di eXtreme Programming
 
TDD Adozione
TDD AdozioneTDD Adozione
TDD Adozione
 
Unit Tests VS End To End Tests
Unit Tests VS End To End TestsUnit Tests VS End To End Tests
Unit Tests VS End To End Tests
 
Detailed Model Capture
Detailed Model CaptureDetailed Model Capture
Detailed Model Capture
 
Test Driven Development for iOS
Test Driven Development for iOSTest Driven Development for iOS
Test Driven Development for iOS
 
Testing
TestingTesting
Testing
 
Fe05 test drivenjavascriptdevelopment
Fe05   test drivenjavascriptdevelopmentFe05   test drivenjavascriptdevelopment
Fe05 test drivenjavascriptdevelopment
 
Total Testing in DevOps
Total Testing in DevOpsTotal Testing in DevOps
Total Testing in DevOps
 
Software Testing & Test Driven Development
Software Testing & Test Driven DevelopmentSoftware Testing & Test Driven Development
Software Testing & Test Driven Development
 
Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...
Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...
Webinar: “Testing automatico: la scelta vincente per ottenere una riduzione d...
 
Unit testing in Visual Studio 2013
Unit testing in Visual Studio 2013Unit testing in Visual Studio 2013
Unit testing in Visual Studio 2013
 
Il computer dice no!
Il computer dice no!Il computer dice no!
Il computer dice no!
 
Test Driven Development @ Xe.Net
Test Driven Development @ Xe.NetTest Driven Development @ Xe.Net
Test Driven Development @ Xe.Net
 
Codice di qualità con VS2010 (TDD)
Codice di qualità con VS2010 (TDD)Codice di qualità con VS2010 (TDD)
Codice di qualità con VS2010 (TDD)
 
ATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven DevelopmentATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven Development
 
Agilozzi le testa tutte
Agilozzi le testa tutteAgilozzi le testa tutte
Agilozzi le testa tutte
 
Effective Code Transformations in C++
Effective Code Transformations in C++Effective Code Transformations in C++
Effective Code Transformations in C++
 
Pro php refactoring
Pro php refactoringPro php refactoring
Pro php refactoring
 
Convertire estensioni da Joomla! 3 a Joomla! 4
Convertire estensioni da Joomla! 3 a Joomla! 4Convertire estensioni da Joomla! 3 a Joomla! 4
Convertire estensioni da Joomla! 3 a Joomla! 4
 

Similar to TDD patterns and TDD strategies

Unit Test di Gabriele Seroni
Unit Test di Gabriele SeroniUnit Test di Gabriele Seroni
Unit Test di Gabriele SeroniGiuneco S.r.l
 
Introduzione al Test Driven Development
Introduzione al Test Driven DevelopmentIntroduzione al Test Driven Development
Introduzione al Test Driven DevelopmentEnnio Masi
 
Il buon programmatore - consigli pratici per una vita felice
Il buon programmatore - consigli pratici per una vita feliceIl buon programmatore - consigli pratici per una vita felice
Il buon programmatore - consigli pratici per una vita feliceAndrea Dottor
 
PASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL ServerPASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL ServerAlessandro Alpi
 
Java Unit Testing - Introduction
Java Unit Testing - IntroductionJava Unit Testing - Introduction
Java Unit Testing - Introductionfgianneschi
 
A brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA eventA brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA eventPietro Di Bello
 
Detailed Model Capture
Detailed Model CaptureDetailed Model Capture
Detailed Model Capturefcospito
 
CONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERCONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERDotNetCampus
 
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerAlessandro Alpi
 
PASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous IntegrationPASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous IntegrationAlessandro Alpi
 
Delphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del TestingDelphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del TestingMarco Breveglieri
 
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...Alessandro Alpi
 
Creare Suite di Test Automatici intelligenti con Selenium IDE
Creare Suite di Test Automatici intelligenti con Selenium IDECreare Suite di Test Automatici intelligenti con Selenium IDE
Creare Suite di Test Automatici intelligenti con Selenium IDEStefano Trojani
 
Baby Steps TripServiceKata
Baby Steps TripServiceKataBaby Steps TripServiceKata
Baby Steps TripServiceKataAndrea Francia
 
Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...
Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...
Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...Boymix81
 
Workshop Test Drive Development
Workshop Test Drive DevelopmentWorkshop Test Drive Development
Workshop Test Drive DevelopmentCommit University
 

Similar to TDD patterns and TDD strategies (20)

Unit Test di Gabriele Seroni
Unit Test di Gabriele SeroniUnit Test di Gabriele Seroni
Unit Test di Gabriele Seroni
 
Introduzione al Test Driven Development
Introduzione al Test Driven DevelopmentIntroduzione al Test Driven Development
Introduzione al Test Driven Development
 
Il buon programmatore - consigli pratici per una vita felice
Il buon programmatore - consigli pratici per una vita feliceIl buon programmatore - consigli pratici per una vita felice
Il buon programmatore - consigli pratici per una vita felice
 
PASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL ServerPASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL Server
 
Java Unit Testing - Introduction
Java Unit Testing - IntroductionJava Unit Testing - Introduction
Java Unit Testing - Introduction
 
PhpUnit
PhpUnitPhpUnit
PhpUnit
 
A brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA eventA brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA event
 
Detailed Model Capture
Detailed Model CaptureDetailed Model Capture
Detailed Model Capture
 
Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
 
CONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVERCONTINUOUS INTEGRATION CON SQL SERVER
CONTINUOUS INTEGRATION CON SQL SERVER
 
DotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql ServerDotNetCampus - Continuous Integration con Sql Server
DotNetCampus - Continuous Integration con Sql Server
 
PASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous IntegrationPASS Virtual Chapter - SQL Server Continuous Integration
PASS Virtual Chapter - SQL Server Continuous Integration
 
Unit test
Unit testUnit test
Unit test
 
Delphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del TestingDelphi & Dintorni Webinar - Diventa un mago del Testing
Delphi & Dintorni Webinar - Diventa un mago del Testing
 
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
DevOpsHeroes 2016 - Realizzare Continouous Integration con SQL Server e Visua...
 
Creare Suite di Test Automatici intelligenti con Selenium IDE
Creare Suite di Test Automatici intelligenti con Selenium IDECreare Suite di Test Automatici intelligenti con Selenium IDE
Creare Suite di Test Automatici intelligenti con Selenium IDE
 
Baby Steps TripServiceKata
Baby Steps TripServiceKataBaby Steps TripServiceKata
Baby Steps TripServiceKata
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...
Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...
Presentazione della Tesi di Laurea Specialistica : STRUMENTI PER LA GENERAZIO...
 
Workshop Test Drive Development
Workshop Test Drive DevelopmentWorkshop Test Drive Development
Workshop Test Drive Development
 

TDD patterns and TDD strategies

  • 1. TDD Patterns and TDD Strategies Alessandro Ceseno contact me, my website is: www.alexceseno.it Add me on Linkedin: http://www.linkedin.com/in/alessandroceseno
  • 2. TDD Patterns Test Come fare TDD Aggiungi un test Fai fallire un test (barra rossa) Modica il test per vedere la barra verde (tutti i test eseguiti con successo) Refactoring verificando che: - funzioni - non vi é duplicazione di codice
  • 3. Isolated Test Come capire se funziona la tua classe? Scrivi un test automatico. Il tuo test è isolato se non da problemi: nell' essere eseguito in modo concorrente con altri test non si basa su un altro test (ogni test dovrebbe ricreare il suo contesto e non dipendere da un altro test) non si basa su un sistema esterno (FS, Network,etc.) non necessita di un ambiente con una particolare configurazione (“It worked on my machine!”) se fallisce non test il messaggio di errore non indica chiaramente perchè fallisce il test
  • 4. Test list Crea una lista dei test Mentre scrivi test e codice applicativo, se individui altri test aggiungili alla tua lista di test
  • 5. Test First Scrivi il test prima del codice applicativo Qual'e il prossimo test? Il prossimo test è quello che ti insegna qualcosa e quello in cui ti senti più confidente
  • 6. Test Data Quali dati per il test si devono utilizzare? Il codice di test dovrebbe essere il più leggibile e semplice possibile, quindi la struttura dei dati di test da utilizzare è quella che consente leggibilità e semplicità
  • 7. Evident Data I risultati che ci si aspetta e i risultati attuali devono essere chiari ed evidenti
  • 8. TDD Strategies I tre approcci principali di implementazione e design nel TDD: - Write the obvious implementation (Scrivi il caso più evidente e più semplice) - Fake it (till you make it). Essendo una tecnica incrementale, inizia anche con un fake test. Generalizza solo quando hai due o tre esempi di test - Triangulate. Il passo successivo è l'implementazione dell'algoritmo corretto.
  • 9. Considerazioni: Considerare i test affinchè non vi siano ridondati test, i test ridondanti sono test che non creano nuove distinzioni di comportamento. redundancy code --> può generare eccessivi problemi di manutenzione quindi anche redundancy test --> possono generare eccessivi problemi di manutenzione Arrivi al design desiderato solo rimuovendo la duplicazione,
  • 10. Il TDD è un modo di gestire la "paura" nello sviluppo? È un modo di gestire il coraggio. Ti consente di fare tentativi semplici e corti come numero di linee di codice, tentativi che ti consentono di capire il funzionamento in un tempo relativamente breve. Consentono una miglior comunicazione (perchè i test si capisco, o meglio si dovrebbero capire, se il TDD è fatto bene)
  • 11. Se hai un test "grande" che si rompe, introduci un test "piccolo" (in questo modo isoli il problema), risolvi il problema e poi reintroduci il test grande. Broken test: viene utilizzato affinchè quando si ritorna su una sessione di programmazione si sa esattamente da dove iniziare.
  • 12. Break: fare una pausa quando si sente di aver bisogno di una pausa. Cheap Desk, Nice Chair.
  • 13. Come individuare test scritti male: codice di setup con molte linee duplicazione di codice che vi è nel setup nelle altre parti della classe test unitari lunghi da eseguire test fragile: i test si rompono ma non si sa il perchè si rompono
  • 14. Bibliografia: Kent Beck - Test Driven Development: By Example
  • 15. TDD Patterns and TDD Strategies Alessandro Ceseno contact me, my website is: www.alexceseno.it Add me on Linkedin: http://www.linkedin.com/in/alessandroceseno