Behaviour Driven Development
using Behat
Isn’t it obvious…???
○

What test should I write next?


○

How do I know when I’ve written the last test?


○

Am I writi...
“

If you can't explain it simply, you
don't understand it well enough


!

Albert Einstein

”
Why BDD?
○

Write Human-readable stories that describe the behaviour of your application


○

Focuses the communication be...
BEHAT
INSTALL
○

Composer


○

PHAR


○

GIT

INIT
○

mkdir Calculator

○

cd Calculator

○

behat --init

./features

/bo...
Gherkins
The Basics
Feature - Gherkins
# features/BananaCalculator.features

# Describe the business value of this feature

Feature: Banana Ca...
Scenario - Gherkins
# features/BananaCalculator.features

# Describe the business rules with scenarios

Scenario: Will add...
Steps - Gherkins
# features/BananaCalculator.features

# Describe the steps

Given I have 3 Bananas

When I add 5 Bananas
...
Example
Feature: Banana Calculator

As Bob the Banana merchant,

I want a calculator that can add the amount of bananas

s...
Scenario Outline
Passing Parameters and Tagging
@BeforeSuite
Managing Sub-Context
○

Context files can get really big really fast


○

Certain steps are repeated across multiple Featu...
Mink
test in browser
Mink
In order to test, that our web application behaves correctly, we need a way to simulate this
interaction between brow...
Goutte
○

Headless Browser


○

No JS support


○

Good for testing REST API
Selenium
○

JS Support

○

Can run multiple browser

○

Need to start Selenium RC

○

Not Headless

○

Need to load Driver...
Sahi
○

JS Support (kinda)


○

Can run Multiple browsers


○

Need to setup localhost proxy
in browser


○

Not headless
...
PhantomJS
○

JS Support


○

Headless browser


○

Pure Awesomeness


!
phantomjs --webdriver=8643
DEMO
BDD Anti-Patterns
just don’t
When i fill in 'input.flooble-widgets[:first]' with 'FooBar'
○

Write BDD in the domain language


○

You should never see...
Anti-pattern
When I subscribe to the newsletter
rather than
And I set the value of 'input#newsletter-signup-checkbox' to '...
And I wait 10 seconds
○

This is not a requirement


○

Roll up the execution into the page element
Try this
public function search($keywords)

{

$searchForm = $this->find('css', 'form#search');



if (!$searchForm) {

th...
IN CONCLUSION
BDD & TDD = BFF
Thank you
BDD using behat
BDD using behat
BDD using behat
BDD using behat
BDD using behat
BDD using behat
BDD using behat
Upcoming SlideShare
Loading in...5
×

BDD using behat

1,083

Published on

It's not obvious what the stake holders really want. How do you know what tests to write? How to you know that you've written the last test? Are you writing the correct code? These are all questions that developers have to answer on a daily basis. BDD can help you and your PO answers these questions faster and with more accuracy. Behat is the BDD framework for PHP that makes it easy to get started with your feature development.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,083
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "BDD using behat"

  1. 1. Behaviour Driven Development using Behat
  2. 2. Isn’t it obvious…??? ○ What test should I write next? ○ How do I know when I’ve written the last test? ○ Am I writing the right code?
  3. 3. “ If you can't explain it simply, you don't understand it well enough ! Albert Einstein ”
  4. 4. Why BDD? ○ Write Human-readable stories that describe the behaviour of your application ○ Focuses the communication between the business and the developers ○ Code is self documenting ○ Code is easier to maintain
  5. 5. BEHAT INSTALL ○ Composer ○ PHAR ○ GIT INIT ○ mkdir Calculator ○ cd Calculator ○ behat --init ./features
 /bootstrap
 FeatureContext.php
  6. 6. Gherkins The Basics
  7. 7. Feature - Gherkins # features/BananaCalculator.features # Describe the business value of this feature Feature: Banana Calculator As Bob the Banana merchant,
 I want a calculator that can add the amount of bananas
 so that I can know how many bananas I currently have
  8. 8. Scenario - Gherkins # features/BananaCalculator.features # Describe the business rules with scenarios Scenario: Will add 2 banana amounts
  9. 9. Steps - Gherkins # features/BananaCalculator.features # Describe the steps Given I have 3 Bananas When I add 5 Bananas Then I should have 8 Banana
  10. 10. Example Feature: Banana Calculator As Bob the Banana merchant,
 I want a calculator that can add the amount of bananas
 so that I can know how many bananas I currently have Scenario: Will add 2 banana amounts
 Given I have 3 Bananas
 When I add 5 Bananas
 Then I should have 8 Banana
  11. 11. Scenario Outline
  12. 12. Passing Parameters and Tagging
  13. 13. @BeforeSuite
  14. 14. Managing Sub-Context ○ Context files can get really big really fast ○ Certain steps are repeated across multiple Feature files
  15. 15. Mink test in browser
  16. 16. Mink In order to test, that our web application behaves correctly, we need a way to simulate this interaction between browser and web application in our tests Mink is an open source acceptance test framework for web applications
  17. 17. Goutte ○ Headless Browser ○ No JS support ○ Good for testing REST API
  18. 18. Selenium ○ JS Support ○ Can run multiple browser ○ Need to start Selenium RC ○ Not Headless ○ Need to load Drivers for different browsers ○ Doesn’t play nice at times java -jar selenium-serverstandalone.jar java -jar selenium-serverstandalone.jar Dwebdriver.chrome.driver=
 "/usr/local/bin/chromedriver"
  19. 19. Sahi ○ JS Support (kinda) ○ Can run Multiple browsers ○ Need to setup localhost proxy in browser ○ Not headless ○ Issues with Ajax Request
  20. 20. PhantomJS ○ JS Support ○ Headless browser ○ Pure Awesomeness ! phantomjs --webdriver=8643
  21. 21. DEMO
  22. 22. BDD Anti-Patterns just don’t
  23. 23. When i fill in 'input.flooble-widgets[:first]' with 'FooBar' ○ Write BDD in the domain language ○ You should never see any DOM elements
  24. 24. Anti-pattern When I subscribe to the newsletter rather than And I set the value of 'input#newsletter-signup-checkbox' to '1' and When I search for articles containing the words 'rockets' rather than When I fill in 'input#search-terms' with 'rockets' And I click 'button#search-button'
  25. 25. And I wait 10 seconds ○ This is not a requirement ○ Roll up the execution into the page element
  26. 26. Try this public function search($keywords)
 {
 $searchForm = $this->find('css', 'form#search');
 
 if (!$searchForm) {
 throw new ElementNotFoundException($this->getSession(), 'form', 'css', 'form#search');
 }
 
 $searchForm->fillField('q', $keywords);
 $searchForm->pressButton('Google Search');
 
 return $this->getPage('Search results');
 }
  27. 27. IN CONCLUSION
  28. 28. BDD & TDD = BFF
  29. 29. Thank you
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×