1. Cucumber, le texte qui teste
Cucumber, le texte qui teste
Cyril Mougel
AF83
2 Octobre 2009
2. Cucumber, le texte qui teste
Les tests
1 Les tests
2 Cucumber c’est quoi ?
3 installation
4 utilisation
3. Cucumber, le texte qui teste
Les tests
Pourquoi faire des tests ?
Etre sˆr que ¸a marche
u c
Valider ce que le client veut
Eviter les r´gressions
e
4. Cucumber, le texte qui teste
Les tests
Pourquoi automatiser ses tests ?
Ne pas perdre son temps ` faire toujours les
a
mˆmes clics
e
Temps de test plus court
5. Cucumber, le texte qui teste
Les tests
Qui d´fini les tests ?
e
Le client
Le chef de projet
Le d´veloppeur
e
6. Cucumber, le texte qui teste
Les tests
Quel sont leur langage ?
Le client : Le document texte
Le chef de projet : Le document texte
Le d´veloppeur : Le code
e
7. Cucumber, le texte qui teste
Les tests
Pour aider tout le monde il y a
Cucumber
8. Cucumber, le texte qui teste
Cucumber c’est quoi ?
1 Les tests
2 Cucumber c’est quoi ?
3 installation
4 utilisation
9. Cucumber, le texte qui teste
Cucumber c’est quoi ?
Cucumber c’est quoi ?
Test d’int´gration
e
BDD (Behaviour Driven Development)
H´ritier des Stories de Rspec
e
10. Cucumber, le texte qui teste
Cucumber c’est quoi ?
Format des tests
Business Readable DSL
Fichier texte
11. Cucumber, le texte qui teste
Cucumber c’est quoi ?
Un exemple ?
login.feature
Feature : Login
To ensure the safety of the application
A regular user of the system
Must authenticate before using the app
Scenario : Success Login
Given I have one user " shingara " with
password " tintinpouet "
When I go to / login
And I fill in " login " with " shingara "
And I fill in " password " with " tintinpouet "
And I press " Log In "
Then the request should be success
And I should see an notice message
And I should not see " Administration "
12. Cucumber, le texte qui teste
Cucumber c’est quoi ?
Context
Action
R´sultat
e
13. Cucumber, le texte qui teste
Cucumber c’est quoi ?
Given == Context
Given step
Given / ˆ I h a v e one u s e r ” ( [ ˆ ” ] ∗ ) ” w i t h p a s s w o r d ” ( [ ˆ ” ] ∗ ) ” $ / do | login ,
password |
# CODE q u i c r e e l ’ u t i l i s a t e u r
end
Given / ˆ I h a v e a l o g g e d u s e r ” ( [ ˆ ” ] ∗ ) ” w i t h p a s s w o r d ” ( [ ˆ ” ] ∗ ) ” $ / do | login ,
password |
%{Given I have one user ”#{l o g i n }” with password ”#{p a s s w o r d }”}
# CODE q u i r e m p l i l e f o r m u l a i r e e t l e v a l i d e
end
14. Cucumber, le texte qui teste
Cucumber c’est quoi ?
When == Action
When step
When / ˆ I f o l l o w ” ( . ∗ ) ” $ / do | link |
@response = click_link ( link )
end
When / ˆ I f i l l i n ” ( . ∗ ) ” w i t h ” ( . ∗ ) ” $ / do | field , value |
@response = fill_in ( field , : with = value ) >
end
15. Cucumber, le texte qui teste
Cucumber c’est quoi ?
Then == R´sultat
e
Then step
Then / ˆ I s h o u l d n o t s e e ” ( [ ˆ ” ] ∗ ) ” $ / do | text |
webr at_session . response . body . to_s . should_not =˜ /#{t e x t }/ m
end
Then / ˆ I s h o u l d s e e an ? (w+) m e s s a g e $ / do | message_type |
webr at_session . response . should have_xpath ( ” / / ∗ [ @ c l a s s =’#{ m e s s a g e t y p e } ’ ] ” )
end
16. Cucumber, le texte qui teste
installation
1 Les tests
2 Cucumber c’est quoi ?
3 installation
4 utilisation
17. Cucumber, le texte qui teste
installation
installation
gem install rspec rspec-rails cucumber webrat
ruby script/generate cucumber
18. Cucumber, le texte qui teste
installation
features/
login.feature
step definitions/
login steps.rb
19. Cucumber, le texte qui teste
utilisation
1 Les tests
2 Cucumber c’est quoi ?
3 installation
4 utilisation