際際滷

際際滷Share a Scribd company logo
Functional Testing With
Behat
By - Tahmina Khatoon
Overview
 Behat
 BDD
 Functional Testing
 BDD features and scenarios
 Mink
 Hands on example
What is BEHAT?
Behat
 Designing application: Behat is an open source Behavior Driven Development
framework for PHP
 Functionally testing: It is an automated functional testing system
It allows us to test PHP applications using human-readable sentences to write features and scenarios about
how your applications should behave in order to test out its functionality.
What is Behavior Driven Development?
Behaviour Driven Development
Agile BDD work really well when a developer and either the Agile product owner or
a business analyst sit down together and write pending specs in a plain text editor:
1. The business person specifies behaviors they want to see in the system.
2. The developer asks questions based on their understanding of the system,
while also writing down additional behaviors needed from a development
perspective.
Behaviour Driven Development Process
With BDD we break down our development process into four steps:
1. Define the business value of all of the big feature.
2. Prioritize those with the highest business value first.
3. Take one feature and break it down into all of the different user stories or
scenarios.
4. Write the code for the feature, ie. how it should behave.
What is Functional Testing?
Functional Testing
Functional Testing is a testing technique that is used to test the
features/functionality of the system or Software, should cover all the scenarios
including failure paths and boundary cases.
Behat!!!
Why behat is so popular
 Behat tests are written in plain English phrases which are then combined into human
readable scenarios. This was inspired by Rubys Cucumber project and Gherkin syntax.
 It is capable of testing several types of systems: terminal commands, REST APIs, etc.
 Mink and a browser emulator to enable Behat to test web pages. Mink functions as the
connector between Behat and browser emulators, and provides a consistent testing
API.
 There are several commonly used browser emulators. Some, like Goutte, are very fast,
but does not support JavaScript. Others, like Selenium and Firefox, are full-featured
browsers, but will run more slowly.
Behat test example
Feature: Listing command
In order to change the structure of the folder I am currently in
As a UNIX user
I need to be able see the currently available files and folders there
Scenario: Listing two files in a directory
Given I am in a directory "test"
And I have a file named "foo"
And I have a file named "bar"
When I run "ls"
Then I should get:
"""
bar
foo
"""
BDD Feature
Feature: <short description>
In order to <business value>
As an <user>
I need to be able to <short description of what the user would actually be able to do>
Example
Feature: Authentication
In order to gain access to the site management area
As an admin
I need to be able to login and logout
Scenarios
Background:
Given <pre-requisite>
Scenario: <scenario short description>
Given <pre-requisite>
When <user action>
Then <expected result>
Step Definition
 Given some precondition
 And some other precondition
 When some action by the actor
 And some other action
 And yet another action
 Then some testable outcome is achieved
 And something else we can check happens too
Test suites
A test suite represents a group of concrete features together with the information
on how to test them.
Lets start coding
Questions?
Thank you :)

More Related Content

Functional testing with behat

  • 2. Overview Behat BDD Functional Testing BDD features and scenarios Mink Hands on example
  • 4. Behat Designing application: Behat is an open source Behavior Driven Development framework for PHP Functionally testing: It is an automated functional testing system It allows us to test PHP applications using human-readable sentences to write features and scenarios about how your applications should behave in order to test out its functionality.
  • 5. What is Behavior Driven Development?
  • 6. Behaviour Driven Development Agile BDD work really well when a developer and either the Agile product owner or a business analyst sit down together and write pending specs in a plain text editor: 1. The business person specifies behaviors they want to see in the system. 2. The developer asks questions based on their understanding of the system, while also writing down additional behaviors needed from a development perspective.
  • 7. Behaviour Driven Development Process With BDD we break down our development process into four steps: 1. Define the business value of all of the big feature. 2. Prioritize those with the highest business value first. 3. Take one feature and break it down into all of the different user stories or scenarios. 4. Write the code for the feature, ie. how it should behave.
  • 9. Functional Testing Functional Testing is a testing technique that is used to test the features/functionality of the system or Software, should cover all the scenarios including failure paths and boundary cases.
  • 11. Why behat is so popular Behat tests are written in plain English phrases which are then combined into human readable scenarios. This was inspired by Rubys Cucumber project and Gherkin syntax. It is capable of testing several types of systems: terminal commands, REST APIs, etc. Mink and a browser emulator to enable Behat to test web pages. Mink functions as the connector between Behat and browser emulators, and provides a consistent testing API. There are several commonly used browser emulators. Some, like Goutte, are very fast, but does not support JavaScript. Others, like Selenium and Firefox, are full-featured browsers, but will run more slowly.
  • 12. Behat test example Feature: Listing command In order to change the structure of the folder I am currently in As a UNIX user I need to be able see the currently available files and folders there Scenario: Listing two files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """
  • 13. BDD Feature Feature: <short description> In order to <business value> As an <user> I need to be able to <short description of what the user would actually be able to do> Example Feature: Authentication In order to gain access to the site management area As an admin I need to be able to login and logout
  • 14. Scenarios Background: Given <pre-requisite> Scenario: <scenario short description> Given <pre-requisite> When <user action> Then <expected result>
  • 15. Step Definition Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too
  • 16. Test suites A test suite represents a group of concrete features together with the information on how to test them.