SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
Tests unitaires
Approche du développement piloté par les tests




                      1      Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Cedric Gatay
•   EPU DI 2008

•   Orange

•   SRMvision

    @Cedric_Gatay
    cedric@gatay.fr
    cedric.gatay.fr/+


                        2   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Agenda

• Pourquoi ?
• Quels outils ?
• Comment ?
• Quelques bonnes pratiques

                   3     Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
4   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Pourquoi ?
• Le code parfait n’existe pas
• Il est difficile de répondre parfaitement à un
  besoin
• On cherche à réduire les coûts
    Les tests unitaires font partie du quotidien
                 des développeurs

                        5     Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
6   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Quels effets ?

• Le code devient
 • Explicité
 • Organisé
 • Assuré

                    7   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
8   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Des tests ? Mais lesquels ?


• Deux grands types de tests
 • boîte noire
 • boîte blanche

                    9     Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
10   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Tests : Black box

• Tests d’acceptation
 • vérification du point de vue utilisateur
 • également appelés recette utilisateur
 • automatisable par des tests d’IHM
 • long et lourd à mettre en place
                     11    Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
12   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Tests : Black box
• Tests fonctionnel
 • vérification d’un pan fonctionnel
   • respect du cahier des charges
   • assuré par l’équipe qualité
 • automatisable par des tests d’IHM
 • long et lourd à mettre en place
                    13    Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
14   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Tests : White box
• Tests d’intégration
 • validation des algorithmes in situ
 • utilisation d’éléments externes
 • automatisable en écrivant du code
 • simple à mettre en place
 • potentiellement long à exécuter
                    15    Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
16   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Tests : White box
• Tests unitaires
 • validation des algorithmes
 • limité au développement en cours
 • automatisable en écrivant du code
 • simple à mettre en place
 • extrêmement rapide à exécuter
                    17    Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
18   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Comment faire ?

• Test Black box
 • réalisation manuelle
 • outils de simulation dans l’IHM
   • entrées et sorties vérifiées

                     19    Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Comment faire ?

• Test White box
 • réalisation automatique
 • framework d’écritures de tests
   • on produit du code pour tester le code

                    20    Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
Test




Fail   Refactor     Pass




        Code




          21      Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
JUnit

• Test White box
• Créé par Kent Beck et Erich Gamma
 • réalisation automatique
 • vérification sur des postulats simples
 • énormément utilisé dans l’industrie
                     22    Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
23   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
JUnit, exemple

Est ce que la moyenne de 5 et 10 retourne 7,5 ?




                      24      Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
25   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
26   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
27   Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
JUnit

•   La moyenne d'aucune            •   Il doit être impossible
    note doit retourner -1             d'ajouter une note
                                       supérieure à 20!
•   Il doit être impossible
    d'ajouter une note             •   Il doit être possible
    négative!                          d'ajouter 16,5




                              28        Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together
JUnit

• Le calcul de moyenne sur aucune note doit
  lever une PasDeNoteException !
• L’ajout d’une note négative doit lever une
  NoteNegativeException !



                     29     Cedric Gatay - c.gatay@srmvision.com   Pulling ITSM together

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Premier pas avec les tests unitaires

  • 1. Tests unitaires Approche du développement piloté par les tests 1 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 2. Cedric Gatay • EPU DI 2008 • Orange • SRMvision @Cedric_Gatay cedric@gatay.fr cedric.gatay.fr/+ 2 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 3. Agenda • Pourquoi ? • Quels outils ? • Comment ? • Quelques bonnes pratiques 3 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 4. 4 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 5. Pourquoi ? • Le code parfait n’existe pas • Il est difficile de répondre parfaitement à un besoin • On cherche à réduire les coûts Les tests unitaires font partie du quotidien des développeurs 5 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 6. 6 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 7. Quels effets ? • Le code devient • Explicité • Organisé • Assuré 7 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 8. 8 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 9. Des tests ? Mais lesquels ? • Deux grands types de tests • boîte noire • boîte blanche 9 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 10. 10 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 11. Tests : Black box • Tests d’acceptation • vérification du point de vue utilisateur • également appelés recette utilisateur • automatisable par des tests d’IHM • long et lourd à mettre en place 11 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 12. 12 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 13. Tests : Black box • Tests fonctionnel • vérification d’un pan fonctionnel • respect du cahier des charges • assuré par l’équipe qualité • automatisable par des tests d’IHM • long et lourd à mettre en place 13 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 14. 14 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 15. Tests : White box • Tests d’intégration • validation des algorithmes in situ • utilisation d’éléments externes • automatisable en écrivant du code • simple à mettre en place • potentiellement long à exécuter 15 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 16. 16 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 17. Tests : White box • Tests unitaires • validation des algorithmes • limité au développement en cours • automatisable en écrivant du code • simple à mettre en place • extrêmement rapide à exécuter 17 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 18. 18 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 19. Comment faire ? • Test Black box • réalisation manuelle • outils de simulation dans l’IHM • entrées et sorties vérifiées 19 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 20. Comment faire ? • Test White box • réalisation automatique • framework d’écritures de tests • on produit du code pour tester le code 20 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 21. Test Fail Refactor Pass Code 21 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 22. JUnit • Test White box • Créé par Kent Beck et Erich Gamma • réalisation automatique • vérification sur des postulats simples • énormément utilisé dans l’industrie 22 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 23. 23 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 24. JUnit, exemple Est ce que la moyenne de 5 et 10 retourne 7,5 ? 24 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 25. 25 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 26. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 27. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 28. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 29. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 30. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 31. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 32. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 33. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 34. 26 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 35. 27 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 36. JUnit • La moyenne d'aucune • Il doit être impossible note doit retourner -1 d'ajouter une note supérieure à 20! • Il doit être impossible d'ajouter une note • Il doit être possible négative! d'ajouter 16,5 28 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together
  • 37. JUnit • Le calcul de moyenne sur aucune note doit lever une PasDeNoteException ! • L’ajout d’une note négative doit lever une NoteNegativeException ! 29 Cedric Gatay - c.gatay@srmvision.com Pulling ITSM together