Download - Premier pas avec les tests unitaires
Pulling ITSM together Cedric Gatay - [email protected]
Tests unitairesApproche du développement piloté par les tests
Pulling ITSM together Cedric Gatay - [email protected]
Cedric Gatay
• EPU DI 2008
• Orange
• SRMvision
@Cedric_Gatay
cedric.gatay.fr/+
2
Pulling ITSM together Cedric Gatay - [email protected]
Agenda
• Pourquoi ?
• Quels outils ?
• Comment ?
• Quelques bonnes pratiques
3
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
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
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Quels effets ?
• Le code devient
• Explicité
• Organisé
• Assuré
7
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Des tests ? Mais lesquels ?
• Deux grands types de tests
• boîte noire
• boîte blanche
9
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
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
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
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
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
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
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
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
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Comment faire ?
• Test Black box
• réalisation manuelle
• outils de simulation dans l’IHM
• entrées et sorties vérifiées
19
Pulling ITSM together Cedric Gatay - [email protected]
Comment faire ?
• Test White box
• réalisation automatique
• framework d’écritures de tests
• on produit du code pour tester le code
20
Pulling ITSM together Cedric Gatay - [email protected]
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
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
JUnit, exemple
Est ce que la moyenne de 5 et 10 retourne 7,5 ?
24
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
Pulling ITSM together Cedric Gatay - [email protected]
JUnit
• La moyenne d'aucune note doit retourner -1
• Il doit être impossible d'ajouter une note négative!
• Il doit être impossible d'ajouter une note supérieure à 20!
• Il doit être possible d'ajouter 16,5
28
Pulling ITSM together Cedric Gatay - [email protected]
JUnit
• Le calcul de moyenne sur aucune note doit lever une PasDeNoteException !
• L’ajout d’une note négative doit lever une NoteNegativeException !
29