Behat is an open source Behavior Driven Development framework for PHP that allows testing PHP applications using human-readable sentences to write features and scenarios about how applications should behave. It is a functional testing system that covers scenarios including failures and boundaries. Behavior Driven Development breaks development into defining business value, prioritizing features, breaking features into user stories, and writing code for how features should behave. Functional testing ensures all features and functionality of a system are tested, including failure paths and boundaries. Behat is popular for testing various system types using a readable domain-specific language to write tests in plain English phrases combined into scenarios.
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.
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
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.