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