Share
Embed
Transcript
13 slides
-
B Tests fonctionnels en PHP avec @jubianchi @AFUP_Lyon - AFUP
Lyon – 25/07/2012 @tentacode -
B , ’ q ? ( 140 r èr )
« You might think about Behat as a tool to teach your clients about testing, but in reality it’s a tool to teach you about client business. » Konstantin Kudryashov (@everzet) https://speakerdeck.com/u/everzet/p/behat-by-example -
T b b Développeur Client Ecrit les tests Unitaires Fonctionnels
Lit les tests Unitaires Fonctionnels Fonctionnels -
Feature: Login! As a visitor! I should be able to
login using a form! ! Scenario: Login with bad credentials! Given I am on the homepage! And I follow "Log in"! And I press "Log in"! Then I should see "Bad credentials"! ! Given I fill in "username" with "foo"! And I fill in "password" with "bar"! And I press "Log in"! Then I should see "Bad credentials"! Q ? Q ? C ? -
W r w • Lancement des tests • Les tests
sont en échec • Le développeur écrit le code des steps manquants • Lancement des tests • Les tests sont en échec • Le développeur produit les éléments (fonctionnels) nécessaires • Lancement des tests • Les tests passent -
T r / f Les tests fonctionnels ne sont pas
des remplaçants des tests unitaires (et inversement). Le test fonctionnel vous assure qu’une fonctionnalité est conforme aux attentes alors que le test unitaire vous assure que le code mis en place pour l’implémenter est stable et robuste. -
default:! name: pretty,junit! parameters:! output_path: .! ! extensions:! symfony2_extension.phar: ~
! ! mink_extension.phar:! mink_loader: "mink.phar"! base_url: "http://%hostname%/app_test.php"! sahi: ~! goutte: ~! javascript_session: "sahi"! browser_name: %browser%! C r • Configuration des formatters (Junit, HTML, CLI, …) https://github.com/Behat/Behat/tree/master/src/Behat/Behat/Formatter • Configuration des extensions (Mink, Symfony2, …) • Configurations des contexts • Configuration des drivers (Sahi, Selenium, …) -
$ php behat.phar -h ! ! Usage:! behat [--init] [-f|--format="..."]
[--out="..."] [--lang="..."] [--[no-]ansi] [-- [no-]time] [--[no-]paths] [--[no-]snippets] [--[no-]snippets-paths] [-- [no-]multiline] [--[no-]expand] [--story-syntax] [-d|--definitions="..."] [-- name="..."] [--tags="..."] [--cache="..."] [--strict] [--dry-run] [--rerun="..."] [-- append-snippets] [features]! U • --format : Choisissez le format de sortie à la volée (dans certains cas, à utiliser avec –-out) • --lang : Choisissez la langue utilisée pour rédiger vos tests • --definitions : Obtenez la liste des steps disponibles • --tags : Lancez vos tests par lots -
Ar r Behat Drivers Extensions Mink Gherkin Formatters Services Interfaces
Context Projet Context (Steps, tags, …) Formatters -
G r q v . Sp q Behat + Extensions
= Eléments génériques réutilisables Il faut développer une partie spécifique(principalement des contextes contenant les définitions de steps) au projet pour pouvoir utiliser un vocabulaire commun à tous. Feature: Login! As a visitor! I should be able to login using a form! ! Scenario: Login with bad credentials! Given I am on the homepage! And I follow "Log in"! And I press "Log in"! Then I should see a ".alert" element containing "Bad credentials"! -
E r B • Grâce aux extensions http://extensions.behat.org/ • Grâce
aux Contexts/Formatters spécifiques au projet http://docs.behat.org/quick_intro.html#writing-your-step-definitions Q q p : • Utiliser atoum pour générer les assertions https://github.com/mageekguy/atoum/wiki/atoum-et-Behat • Test distribué grâce à Gearman http://extensions.behat.org/gearman/ • Behat Viewer : analyseur de rapport http://behat-viewer-ci.jubianchi.fr -
E r B • Grâce aux extensions http://extensions.behat.org/ • Grâce
aux Contexts/Formatters spécifiques au projet http://docs.behat.org/quick_intro.html#writing-your-step-definitions Q q p : • Utiliser atoum pour générer les assertions https://github.com/mageekguy/atoum/wiki/atoum-et-Behat • Test distribué grâce à Gearman http://extensions.behat.org/gearman/ • Behat Viewer : plateforme d’analyse et de centralisation des rapports http://behat-viewer-ci.jubianchi.fr -
Questions… Merci à l’AFUP Lyon (@AFUP_Lyon), Gabriel Pillet (@tentacode), Konstantin
Kudryashov (@everzet), Ludovic Fleury (@ludofleury), … FIN